[R] attach 'name' argument ignored with a file?
Dear useRs experRts, I have the feeling that the 'name' argument to the attach function is ignored when 'what' is a file name. Here is an example: save(letters, file=letters.RData) letters.env - attach(letters.RData, name=letters) search() letters.env The name on the search path is file:letters.RData. I would expect it to be letters... Is it by design? From the doc I read: name name to use for the attached database. ... The name given for the attached environment will be used by search and can be used as the argument to as.environment. I don't see why that would be restricted when 'what' is a file name. What do you think about it? Should I fill a bug about it or did I mis-read the doc? Regards, Xavier __ R-help@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.
[R] attach
I found the following message maybe help. And I will try it. Hi there, I have just found that the ``attach'' function can get you into trouble when called many times. For example, you have a simulation routine called ``f()'', in which you used ``attach'' and no corresponding ``detach''. Then you call this function many times. You will find that the system performance get slower and slower, because you are making the R search path longer and longer. So be careful when you use attach in a function! Below is a demonstration of this performance loss, you will see a linear growth in CPU time usage. Adding a ``detach()'' call at the end of ``f'' will get rid of this problem. ### f - function(){ theta - list(one=2.0, two=0.3, three=0.4) attach(theta) x - c(one, two, three) sample(x, 1) } test - function(n=400){ timeu - numeric(n) for(i in seq(n)){ timeu[i] - system.time({ resi - f() })[3] } plot(timeu) } test() ## -- Sincerely, Changbin -- [[alternative HTML version deleted]] __ R-help@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.
Re: [R] attach
On Wed, 2009-10-14 at 07:21 +0200, Christophe Dutang wrote: Hi all, I have a question regarding the memory usage for the attach function. Say I have a data.frame inputdat that I create with read.csv. I would like to know what happens on the memory side when I use attach(inputdata) Is there a second allocation of memory for inputdata? Then I'm using eval on a expression which depends on the columns of inputdata. Is it better not to use attach function? Thanks in advance Christophe Well, if you attach a data.frame twice times, it use your memory twice times. I don't use attach I prefer with(data.frame, command) -- Bernardo Rangel Tura, M.D,MPH,Ph.D National Institute of Cardiology Brazil __ R-help@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.
Re: [R] attach
Dieter Menne wrote: Christophe Dutang1 wrote: I would like to know what happens on the memory side when I use attach(inputdata) Is there a second allocation of memory for inputdata? Not, it just guides the syntax. Wrong. There's a virtual copy of data plus a conversion from data frame to attached environment on the search path. If you modify data in either of the original frame or the environment, you will get duplication. Christophe Dutang1 wrote: Is it better not to use attach function? A qualified yes in the sense of do not use it. I think it is used to much in old documentation, presumably because some S eggshells. I use with() if I have a nasty formula to unclutter; it acts locally only and you don't get unwanted side effects. Well, opinions vary. Having to qualify data frame access on each use does tend to get in the way of explorative work, at least it does so for me. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@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.
Re: [R] attach
Christophe Dutang1 wrote: I would like to know what happens on the memory side when I use attach(inputdata) Is there a second allocation of memory for inputdata? Not, it just guides the syntax. Christophe Dutang1 wrote: Is it better not to use attach function? A qualified yes in the sense of do not use it. I think it is used to much in old documentation, presumably because some S eggshells. I use with() if I have a nasty formula to unclutter; it acts locally only and you don't get unwanted side effects. Dieter -- View this message in context: http://www.nabble.com/attach-tp25885494p25886141.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] attach
Hi all, I have a question regarding the memory usage for the attach function. Say I have a data.frame inputdat that I create with read.csv. I would like to know what happens on the memory side when I use attach(inputdata) Is there a second allocation of memory for inputdata? Then I'm using eval on a expression which depends on the columns of inputdata. Is it better not to use attach function? Thanks in advance Christophe -- Christophe Dutang Ph.D. student at ISFA, Lyon, France website: http://dutangc.free.fr __ R-help@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.
[R] attach package
Hello, Is there a solution to attach a package without run the hook function .onAttach() Thanks Jérémy Mazet [[alternative HTML version deleted]] __ R-help@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.
Re: [R] attach package
On 8/26/2009 8:17 AM, Jeremy MAZET wrote: Hello, Is there a solution to attach a package without run the hook function .onAttach() You could modify the source code to remove the hook, but why you'd want to do this, I don't know. Presumably the author of the package had a reason to put the hook there, and the package may not work properly without it. Duncan Murdoch __ R-help@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.