Comments (4)
Great, thank you!
from backports.
TBH, I have a hard time understanding the intended behavior after reading both news and man page.
from backports.
Understandably. There has been a very lengthy discussion about how it should behave r-devel.
As previously, paste0
is just paste
currying the sep
argument to ""
:
paste0 <- function(..., collapse = NULL, recycle0 = FALSE) paste(..., sep = "", collapse = collapse, recycle0 = recycle0)
Only difference is that it now also forwards the recycle0
argument.
paste
with recycle0 = FALSE
(the default) behaves as previously.
To understand the new behavior for recycle0 = TRUE
it helps to think of paste as two different functions by considering the following identity:
paste <==> function(..., sep = " ", collapse = NULL, recycle0 = FALSE)
paste(paste(..., sep = sep, recycle0 = recycle0), collapse = collapse)
Only the inner part of paste
, the one that concatenates that performs an element wise concatenation, is affected by the new recycle0
argument. Previously and now with recycle0 = FALSE
, paste
would not recycle zero-length arguments but replace them by rep("", max(sapply(list(...), length)))
. This means that paste0("Hello", character(0), "!")
would (somewhat unexpectedly) yield "Hello !"
. With the new recycle0 = TRUE
, paste
recycles zero-length arguments just like e.g. +
does for integer
s:
paste0("Hello", character(0), "!", recycle0 = TRUE)
yields character(0)
, just like 1L+integer(0)==integer(0)
or (1:3)+integer(0)==integer(0)
.
you could implement the new paste like this (and paste0 accordingly):
paste <- function(..., sep = " ", collapse = NULL, recycle0 = FALSE) {
if(recycle0 && any(vapply(list(...), length, FUN.VALUE = integer(1))==0)) {
paste(sep = sep, collapse = collapse) # for argument checking
if (is.null(collapse)) character(0) else ""
} else base::paste(..., sep = sep, collapse = collapse)
}
In words: if recycle0
is set to true & there are zero-length arguments paste
returns the empty string "" if collapse is a string and to the zero-length value character(0) when collapse = NULL.
See also my SO question for an application.
from backports.
This would be indeed nice to have.
from backports.
Related Issues (20)
- Error: install of package 'backports' failed HOT 3
- Install issue with version 1.1.8 HOT 2
- backports not built for Windows release and oldrel after 1.1.7 HOT 1
- Add str2lang and str2expression to README HOT 1
- asplit() added in R 3.6.0
- Unable to install 1.1.9 from cran (windows) HOT 1
- Add isNamespaceLoaded added in 3.2.0 HOT 1
- removeSource started accepting language objects in R 3.6.0 HOT 1
- Add backport for tools::R_user_dir() HOT 1
- README.md: Make available on CRAN HOT 1
- Move `master` branch to `main` HOT 1
- How about `grDevices` (e.g., `palette()`, `palette.colors()`) HOT 2
- Small inconsistency with empty names in backports of `...names()` HOT 5
- .libPaths() for R < 4.1 HOT 1
- Missing backport for str2lang?
- Native Pipe Backport HOT 2
- CI tests fail in R 3.3 HOT 2
- Add null coalescing operator `%||%` to be introduced with R 4.4.0 HOT 1
- Add missing backport for sort_by() (R v4.4.0)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backports.