Computing on the Language
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
And now for something a bit more esoteric….
I recently wrote a function to deal with a strange problem. Writing the function ended up being a fun challenge related to computing on the R language itself.
Here’s the problem: Write a function that takes any number of R objects as arguments and returns a list whose names are derived from the names of the R objects.
Perhaps an example provides a better description. Suppose the function is called ‘makeList’. Then
x <- 1 y <- 2 z <- "hello" makeList(x, y, z)
returns
list(x = 1, y = 2, z = "hello")
It originally seemed straightforward to me, but it turned out to be very much not straightforward.
Note that a function like this is probably most useful during interactive sessions, as opposed to programming.
I challenge you to take a whirl at writing the function, you know, in all that spare time you have. I’ll provide my solution in a future post.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.