We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
Thanks so much for the kind words, Andrea!
That's an interesting scenario. I hadn't tried running cross_df() with arguments of unequal length before, but at your suggestion I took a look. Although, it seems to do exactly as I expected: return every combination of arg1 and arg2.
Essentially, given your example, it returns
myFunction(1, 2)
myFunction(1, 4)
myFunction(1, 6)
...all the way to...
myFunction(9, 10)
myFunction(9, 11)
Were you describing a different behavior?
No, no. Just thinking to extend the user case in your blog. R usually recycles vectors of different lengths, but here it goes differently and a real complete enumeration is provided.
Best
A.
Good article!.
But in the very last example:
> arg1 <- c(1, 3, 5, 9)
> arg2 <- c(2, 4, 6, 10)
> crossArg <- cross_df(arg1, arg2)
Error: The filter function must return TRUE or FALSE
Amber,
am I missing something?.
SFdisqus
latest versions of R and Rstudio/Linux
You're absolutely right! I completely forgot that `cross_df()` expects a list of named arguments. This is now fixed in the post. Thank you for pointing it out!!
Lovely done, really interesting, Amber! +1
It might be interesting to add some words on recycling, though.
> arg1 <- c(1, 3, 5, 9)
> arg2 <- c(2, 4, 6, 10, 11) #arg1 and arg2 differ ....
> crossArg <- cross_df(arg1, arg2)