Marco Barbàra
2011-May-29 19:20 UTC
[R] Why do not prevent users from creating a local copy of c() ?
Hi all, sometime in the past I accidentaly created a copy of the c() primitive function inside my ``laboratory'' workspace, which I normally use to experiment and learn. As a consequence, c() stopped to work correctly and started to return lists of symbols instead of vectors, and today I had to spend much time to seek out that the problem was in that specific workspace (if only I had known in advance ... ). The weird thing is that if I now recreate a local copy of c(), the function does continue to work correctly. Anyway, my question is: could be possible to prevent users from doing such dangerous things? Thanks, Marco.
jim holtman
2011-May-29 20:00 UTC
[R] Why do not prevent users from creating a local copy of c() ?
There is no way to prevent a user from messing up. No matter how many things you put in to prevent such occurances, I have always found that users find new ways to use your system that you never considered. There is always the 'conflicts()' function that might help:> # create my 'c' > c <- function(x) x > conflicts()[1] "body<-" "c" "setwd" "summary">On Sun, May 29, 2011 at 3:20 PM, Marco Barb?ra <jabbba at gmail.com> wrote:> Hi all, > > sometime in the past I accidentaly created a copy of the c() > primitive function inside my ``laboratory'' workspace, which I > normally use to experiment and learn. As a consequence, c() stopped to > work correctly and started to return lists of symbols instead of > vectors, and today I had to spend much time to seek out that the problem > was in that specific workspace (if only I had known in advance ... ). > > The weird thing is that if I now recreate a local copy of c(), the > function does continue to work correctly. > > Anyway, my question is: could be possible to prevent users from doing > such dangerous things? > > Thanks, Marco. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?
Joshua Wiley
2011-May-29 20:00 UTC
[R] Why do not prevent users from creating a local copy of c() ?
Hi Marco, I am sure theoretically it would be possible to make it so that copies could not be made of base (or core) functions, but users will always be able to shoot themselves in the foot if they try hard enough. I think the usual recommendation is just not to use common function names for your own functions/data. If you write scripts instead of just directly using the console, you do not need to save the workspace, which mitigates a whole slew of potential things you did at some prior time and have long since forgotten biting you in the posterior. You can still save data, but by using clean sessions, you are more aware of what has been done. Cheers, Josh On Sun, May 29, 2011 at 12:20 PM, Marco Barb?ra <jabbba at gmail.com> wrote:> Hi all, > > sometime in the past I accidentaly created a copy of the c() > primitive function inside my ``laboratory'' workspace, which I > normally use to experiment and learn. As a consequence, c() stopped to > work correctly and started to return lists of symbols instead of > vectors, and today I had to spend much time to seek out that the problem > was in that specific workspace (if only I had known in advance ... ). > > The weird thing is that if I now recreate a local copy of c(), the > function does continue to work correctly. > > Anyway, my question is: could be possible to prevent users from doing > such dangerous things? > > Thanks, Marco. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/