Re: [R] How to remove all objects except a few specified objects?
Thanks Josh and Karl. function dnrm() works well for my purpose. -- View this message in context: http://r.789695.n4.nabble.com/How-to-remove-all-objects-except-a-few-specified-objects-tp2335651p2337398.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.
Re: [R] How to remove all objects except a few specified objects?
Thanks to De-Jian and Peter. Peter's way is neat and cool! -- View this message in context: http://r.789695.n4.nabble.com/How-to-remove-all-objects-except-a-few-specified-objects-tp2335651p2338221.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.
Re: [R] How to remove all objects except a few specified objects?
a - 1 b - 2 c - 3 ls()[-a] # set minus to all the objects you want to retain rm(list = ls()[-a] # will remove all the objects - except a ls() # presto -- View this message in context: http://r.789695.n4.nabble.com/How-to-remove-all-objects-except-a-few-specified-objects-tp2335651p2336200.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.
Re: [R] How to remove all objects except a few specified objects?
2010/8/24 500600 romu...@gmail.com: a - 1 b - 2 c - 3 ls()[-a] # set minus to all the objects you want to retain rm(list = ls()[-a] # will remove all the objects - except a ls() # presto Only because a=1 and a is the first item in the list! Not because you are doing '-a'! If a is 0 then nothing gets deleted, and if a isn't numeric vector then it just fails. If you want to do it by name, use match Barry __ 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] How to remove all objects except a few specified objects?
or use #not checked rm(setdiff(ls(),c(a, b)) On Aug 24, 2010, at 4:55 AM, Barry Rowlingson wrote: 2010/8/24 500600 romu...@gmail.com: a - 1 b - 2 c - 3 ls()[-a] # set minus to all the objects you want to retain rm(list = ls()[-a] # will remove all the objects - except a ls() # presto Only because a=1 and a is the first item in the list! Not because you are doing '-a'! If a is 0 then nothing gets deleted, and if a isn't numeric vector then it just fails. If you want to do it by name, use match Barry __ 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-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] How to remove all objects except a few specified objects?
If you are going to be doing this a lot, you may want to consider making a little function. Here is an example 'do not remove' function. It defaults to the global environment, but you can always change it. Also, if you try to keep a variable name that does not exist, it will throw an error and not remove anything. My assumption is that when one of the names the user typed does not match a current object, the user made a typo. dnrm - function(vars, envir = .GlobalEnv) { vars - c(vars, dnrm) keep - match(x = vars, table = ls(envir = envir)) if(any(is.na(keep))) { stop(paste(Some of the variables were not found in, environmentName(envir))) } rm(list = ls(envir = envir)[-keep], envir = envir) cat(Removed all but, length(keep), objects from, environmentName(envir), fill = TRUE) } Cheers, Josh On Mon, Aug 23, 2010 at 12:00 PM, Cheng Peng cp...@usm.maine.edu wrote: How to remove all R objects in the RAM except for a few specified ones? rm(list=ls()) removes all R objects in the R work space. Another question is that whether removing all R objects actually releases the RAM? Thanks. -- View this message in context: http://r.789695.n4.nabble.com/How-to-remove-all-objects-except-a-few-specified-objects-tp2335651p2335651.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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.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.
Re: [R] How to remove all objects except a few specified objects?
Thanks for all suggestions from Roman (?= 500600[via R]), Barry and Jim. It seems that ls()[-objectname] didn't work even on numeric matrices and user made functions. I will work with Jim's advice on using grep() and gc() to see whether it works. -- View this message in context: http://r.789695.n4.nabble.com/How-to-remove-all-objects-except-a-few-specified-objects-tp2335651p2336653.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.
Re: [R] How to remove all objects except a few specified objects?
Hi Cheng, Check out the keep() function in package:gdata. And to be sure the removed objects are really removed from system memory i think you need to run gc(). hth, Karl On 8/23/2010 9:00 PM, Cheng Peng wrote: How to remove all R objects in the RAM except for a few specified ones? rm(list=ls()) removes all R objects in the R work space. Another question is that whether removing all R objects actually releases the RAM? Thanks. -- Karl Brand k.br...@erasmusmc.nl Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ 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] How to remove all objects except a few specified objects?
If your specified objects have a certain pattern, you can use the parameter pattern in ls() to remove or keep it. rm(list=ls(..., pattern=your_pattern)) If not, possibly you have to manually specify them. On 2010-8-24 3:00, Cheng Peng wrote: How to remove all R objects in the RAM except for a few specified ones? rm(list=ls()) removes all R objects in the R work space. Another question is that whether removing all R objects actually releases the RAM? Thanks. __ 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] How to remove all objects except a few specified objects?
Tena korua ls()[!(ls() %in% c('keepThis','andThis'))] will give the elements excluding 'keepThis' and 'andThis'. Thus rm(list= ls()[!(ls() %in% c('keepThis','andThis'))]) will remove everything except these two objects, and hidden objects. It you want to remove the hidden objects as be use ls(all=TRUE). HTH Peter Alspach -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Dejian Zhao Sent: Wednesday, 25 August 2010 1:32 p.m. To: r-help@r-project.org Subject: Re: [R] How to remove all objects except a few specified objects? If your specified objects have a certain pattern, you can use the parameter pattern in ls() to remove or keep it. rm(list=ls(..., pattern=your_pattern)) If not, possibly you have to manually specify them. On 2010-8-24 3:00, Cheng Peng wrote: How to remove all R objects in the RAM except for a few specified ones? rm(list=ls()) removes all R objects in the R work space. Another question is that whether removing all R objects actually releases the RAM? Thanks. __ 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-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.