I'm having that problem where I am sometimes using an object that's from a previous workspace when I don't want to be doing that. I was thinking of putting rm(objects=ls()) in my first.R function But, the problem with doing this, is that it doesn't prompt you with "are you sure" and there could be very rare cases where I don't want to delete the workspace ? Is there a way to make the cleaning of the workspace automatic but still prompt you ? I guess I can always just try to remember to manually do rm(objects=ls())when I start up in whatever workspace I am in but I don't think I can trust my memory. Thanks. -------------------------------------------------------- This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}
On Mon, 2006-11-27 at 18:29 -0500, Leeds, Mark (IED) wrote:> I'm having that problem where I am sometimes using an object that's from > a previous workspace when I don't want to be doing that. I was thinking > of putting rm(objects=ls()) in my first.R function But, the problem with > doing this, is that it doesn't prompt you with "are you sure" and there > could be very rare cases where I don't want to delete the workspace ? Is > there a way to > make the cleaning of the workspace automatic but still prompt you ? I > guess I can always just try to remember to manually > do rm(objects=ls())when I start up in whatever workspace I am in but I > don't think I can trust my memory. Thanks.I assume you are saving your workspace when exiting R, and then when restarting R in same directory it is auto loading the saved workspace? If so, try not saving the workspace at the end of the session when quitting, but explicitly save the objects you wish to save using save() and load() it when restarting. You might need to locate and delete the file .Rdata in the working directory first, before you start R for example, to stop it being loaded when you start R again. Alternatively, give it a new name with a .Rdata extension, so you can load the workspace again if needed. You might also want save.image if you are interested in saving workspaces rather than individual objects. This way you are in control of what is and is not saved/reloaded and you won't have to rely on your memory. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC & ENSIS, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/cv/ London, UK. WC1E 6BT. [w] http://www.ucl.ac.uk/~ucfagls/ %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Hi ! I am trying to read in 1000 really small text files. When on adams, R bails out after reading 125 files with the error message Error in textConnection(readLines(f, n = 2)) : all connections are in use I have traced this to a call to the scan() function which is at that point trying to read tge 126th data file. I have tried specifically closing each connection i open after loading a file to avoid this. But that fails and I get the same error message. I googled and hit on a conversation between Professor Ripley and Dirk Eddelbuettel <https://stat.ethz.ch/pipermail/r-sig-db/2006-July/000208.html> that talks about a similar problem - there the suggestion made which apparently worked was to fix a function called mysqlImportFile(). But i dont see this function being even in memory now. Peculiarly, I am able to read upto 200 files when i am in windows. I am hoping someone with more expereince with linux and/or RSQLite will have some suggestions. thanks! Alex _________________________________________________________________ Fixing up the home? Live Search can help
I believe the usal advice here is to store data and associated functions together in separate .Rdata datasets (workspaces) via ?save. You can ?load them as needed. Bert Gunter Genentech Nonclinical Statistics South San Francisco, CA 94404 -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Leeds, Mark (IED) Sent: Monday, November 27, 2006 3:30 PM To: r-help at stat.math.ethz.ch Subject: [R] automatic cleaning of workspace I'm having that problem where I am sometimes using an object that's from a previous workspace when I don't want to be doing that. I was thinking of putting rm(objects=ls()) in my first.R function But, the problem with doing this, is that it doesn't prompt you with "are you sure" and there could be very rare cases where I don't want to delete the workspace ? Is there a way to make the cleaning of the workspace automatic but still prompt you ? I guess I can always just try to remember to manually do rm(objects=ls())when I start up in whatever workspace I am in but I don't think I can trust my memory. Thanks. -------------------------------------------------------- This is not an offer (or solicitation of an offer) to buy/se...{{dropped}} ______________________________________________ R-help at stat.math.ethz.ch 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.
I believe the following function is something like what Mark was looking for. The previously posted answers to his inquiry were more of the form ``Do this instead of what you want to do.'' rather than ``Here's how to do what you want to do.'' clean <- function() { # Function clean. lll <- ls(pos=1) for(xxx in lll) { pmpt <- paste("remove ", xxx, "? ",sep="") ans <- readline(pmpt) if(ans == "y") rm(list=xxx, pos = 1) } invisible() } Usage: clean() cheers, Rolf Turner rolf at math.unb.ca P. S. Moral of the story: If you want to do something in R and the facility is not built in, it is usually very easy to roll your own. Often it's actually easier to roll your own than to *find* pre-existing facilities. R. T.
You can avoid loading .Rdata at start-up without deleting the .Rdata file by adding the --no-restore option to the R command. I have that, and additionally, --no-save, in my shortcut for the Rgui.exe command. I use explicit save() and load() in my scripts to save objects that are expensive to compute. Andy From: Leeds, Mark (IED)> > I'm having that problem where I am sometimes using an object > that's from a previous workspace when I don't want to be > doing that. I was thinking of putting rm(objects=ls()) in my > first.R function But, the problem with doing this, is that it > doesn't prompt you with "are you sure" and there could be > very rare cases where I don't want to delete the workspace ? > Is there a way to make the cleaning of the workspace > automatic but still prompt you ? I guess I can always just > try to remember to manually do rm(objects=ls())when I start > up in whatever workspace I am in but I don't think I can > trust my memory. Thanks. > -------------------------------------------------------- > > This is not an offer (or solicitation of an offer) to > buy/se...{{dropped}} > > ______________________________________________ > R-help at stat.math.ethz.ch 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. > > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}