View source: R/params_recycle.R
| recycle | R Documentation |
recycle is called within a function and ensures the parameters in the
calling function are all the same length by repeating them using rep. This
function alters the environment from which it is called. It is stricter than
R recycling in that it will not repeat vectors other than length one to match
the longer ones, and it throws more informative errors.
recycle(..., .min = 1, .env = rlang::caller_env())
... |
the variables to recycle |
.min |
the minimum length of the results (defaults to 1) |
.env |
the environment to recycle within. |
NULL values are not recycled, missing values are ignored.
the length of the longest variable
testfn = function(a, b, c) {
n = recycle(a,b,c)
print(a)
print(b)
print(c)
print(n)
}
testfn(a=c(1,2,3), b="needs recycling", c=NULL)
try(testfn(a=c(1,2,3), c=NULL))
testfn(a=character(), b=integer(), c=NULL)
# inconsistent to have a zero length and a non zero length
try(testfn(a=c("a","b"), b=integer(), c=NULL))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.