I'm new to R and am writing a library of functions all of which act on a set of 6 linked dataframes. I'd like to avoid having each function have to be called explicitly with the names of the dataframes, e.g. foo(df1,df2,df3,df4,df5,df6, otherargs....). But to do this I need to be able to set default names for the dataframe argument names in the function like: function(df1=dataframename1.....) which I can't get to work, or access the dataframes in the global environment from within my functions which just seems wrong. What is the correct "R-ish" way of dealing with this?
Asked
Active
Viewed 269 times
0
-
2Can you provide a little more detail and some minimal example code to demonstrate what exactly you're trying to do? (See http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for ideas) – HFBrowning Jan 25 '17 at 00:43
-
just write your functions to accept an argument that is a vector of df names. then you only need specify df names once. I can write out a complete answer if you are unclear on my meaning – JustGettinStarted Jan 25 '17 at 00:43
-
2and/or supply your dfs as a list to your functions – JustGettinStarted Jan 25 '17 at 00:44
-
Please [post a repo of your problem](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Most likely there is an "`R`" way to approach your problem that will be easier than having to pass 6 data frames to a function. – Barker Jan 25 '17 at 00:52
-
1See, e.g., [How do I make a list of data frames?](http://stackoverflow.com/q/17499013/903061) for tips. Without changing your function you could use `do.call(foo, args = c(list_of_data_frames, otherargs))`, but it might be best to write your function to expect a list of data frames as the input. – Gregor Thomas Jan 25 '17 at 00:58