Function argument as a part of the output name

Hi RStudio Community,

I am new to writing functions in R and am not certain if what I am trying to do is possible. I have the below function

convert.todf <- function(y) {
  `y` <<-

I am trying to make it such that the new output dataframe will have the same name as the argument which I put in. I've tried putting my argument y as y, (y), "y", and simply as y, but none of those have been working.

Just for a bit of context, the data structure of the arguments I will be using are environments and they are named using numbers (1,2,3). I am planning on using this for multiple arguments theoretically by putting a range of 1:58 as my argument, and hope to get an output of 58 separate data frames using this function.

Any advice/help is appreciated and thank you in advance!

You probably know that you can put the 58 data.frames in a list and retrieve them by a sequence number or a name. Why do you need the environments?

I don't want them in a list, I want them as separate dataframes.

You can use the assign function. For example


And in combination with deparse and substitute


maybe I haven't understood but it sounds like you are hoping to coerce 'environments' into 'data.frames', I don't think this is trivially possible, with anything as simple as a call as it would depend on the content of the environment and your knowledge of that...

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.