Skip to content

use name (not values!) of a dataframe inside a funktion

1 message · PIKAL Petr

#
Hi

Maybe others can help you but here is my comment. I already use R for many years and never used such construction. Objects in global environment shall not be modified by functions it is a bad practice. Imagine you have some data frame you prepared and controlled in many steps and use some function from a package. 

If this function scrambles object without warning and the result cannot be easily repaired I would be tempted to curse the function with many nasty four letter words.

When I want to change some data by a function I use

fff <- function(x, no=2) {
x[,no]<-factor(x[, no])
x
}
 
dfb.f <- fff(dfb)

In this case I will end with old object dfb and new object dfb.f. Of course it is possible to use

dfb <- fff(dfb)

and in this case dfb object is changed

Petr