Re: [R] subsetting ls() as per class...
dear peter, Its workingthanks a lot... yours sincerely, AKSHAY M KULKARNI From: Peter Langfelder Sent: Saturday, July 28, 2018 11:41 AM To: akshay...@hotmail.com Cc: r-help Subject: Re: [R] subsetting ls() as per class... Looking at ?rm, my solution would be something like rm(list = grep("\\.NS$", ls(), value = TRUE)) But test it since I have not tested it. Peter On Fri, Jul 27, 2018 at 10:58 PM akshay kulkarni wrote: > > dear memebers, >I am using R in AWS linux instance for my > research. I want to remove certain objects from the global environment to > reduce my EBS cost..for example, I want to remove all objects of class "xts", > "zoo". Is there any way to automate this, instead of removing the objects one > by one? > > Basically, I want to subset ls() according to class, and then remove that > subset by using rm function. > > I got to know about mget in SO, but that is not working in my case > > Also, all the above objects end with ".NS". I came to know that you can > remove objects starting with a certain pattern; is there any way to remove > objects ending in a certain pattern? > > very many thanks for your time and effort... > yours sincerely, > AKSHAY M KULKARNI > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] subsetting ls() as per class...
> objClasses <- unlist(eapply(.GlobalEnv, function(x)class(x)[1])) > head(objClasses) f E "function" "environment" df h "tbl_df""function" myData L "list""list" > names(objClasses)[objClasses=="tbl_df"] [1] "df" "out" Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Jul 27, 2018 at 10:58 PM, akshay kulkarni wrote: > dear memebers, >I am using R in AWS linux instance for my > research. I want to remove certain objects from the global environment to > reduce my EBS cost..for example, I want to remove all objects of class > "xts", "zoo". Is there any way to automate this, instead of removing the > objects one by one? > > Basically, I want to subset ls() according to class, and then remove that > subset by using rm function. > > I got to know about mget in SO, but that is not working in my case > > Also, all the above objects end with ".NS". I came to know that you can > remove objects starting with a certain pattern; is there any way to remove > objects ending in a certain pattern? > > very many thanks for your time and effort... > yours sincerely, > AKSHAY M KULKARNI > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] subsetting ls() as per class...
The ll() function of R.oo returns a data.frame with various attributes that you can subset on, e.g. > subset(R.oo::ll(), data.class %in% c("zoo", "xts")) member data.class dimension objectSize 2 fzzoo10 1344 4 sample.xtsxts c(180,4) 10128 5 xzoo 5528 6 x1zoo 5880 7 x2zoo 5496 9 yzoo 5 1040 11 zzooc(5,3) 1184 12 z0zoo 0448 13 z2zooc(4,3)904 14z20zooc(4,0)616 15 z3zoo 8528 16 z4zoo 5592 17 z5zoo 5792 Henrik On Sat, Jul 28, 2018, 08:22 Jeff Newmiller wrote: > You can extract the names into a character vector with ls and then use > grep(..., values=TRUE ) to select which ones you want to remove, and then > pass that list to rm. > > However, due to the way R handles memory you are unlikely to see much > savings by doing this. I would recommend focusing on creating a script or > series of scripts that can allow you to re-create your analysis, and then > restarting R whenever you are ready to reduce memory usage. This will have > the side benefit of leaving you with a verified-complete record of how your > analysis was done. > > On July 27, 2018 10:58:36 PM PDT, akshay kulkarni > wrote: > >dear memebers, > >I am using R in AWS linux instance for my research. I want to remove > >certain objects from the global environment to reduce my EBS cost..for > >example, I want to remove all objects of class "xts", "zoo". Is there > >any way to automate this, instead of removing the objects one by one? > > > >Basically, I want to subset ls() according to class, and then remove > >that subset by using rm function. > > > >I got to know about mget in SO, but that is not working in my case > > > >Also, all the above objects end with ".NS". I came to know that you > >can remove objects starting with a certain pattern; is there any way to > >remove objects ending in a certain pattern? > > > >very many thanks for your time and effort... > >yours sincerely, > >AKSHAY M KULKARNI > > > > [[alternative HTML version deleted]] > > > >__ > >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > >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. > > -- > Sent from my phone. Please excuse my brevity. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] subsetting ls() as per class...
You can extract the names into a character vector with ls and then use grep(..., values=TRUE ) to select which ones you want to remove, and then pass that list to rm. However, due to the way R handles memory you are unlikely to see much savings by doing this. I would recommend focusing on creating a script or series of scripts that can allow you to re-create your analysis, and then restarting R whenever you are ready to reduce memory usage. This will have the side benefit of leaving you with a verified-complete record of how your analysis was done. On July 27, 2018 10:58:36 PM PDT, akshay kulkarni wrote: >dear memebers, >I am using R in AWS linux instance for my research. I want to remove >certain objects from the global environment to reduce my EBS cost..for >example, I want to remove all objects of class "xts", "zoo". Is there >any way to automate this, instead of removing the objects one by one? > >Basically, I want to subset ls() according to class, and then remove >that subset by using rm function. > >I got to know about mget in SO, but that is not working in my case > >Also, all the above objects end with ".NS". I came to know that you >can remove objects starting with a certain pattern; is there any way to >remove objects ending in a certain pattern? > >very many thanks for your time and effort... >yours sincerely, >AKSHAY M KULKARNI > > [[alternative HTML version deleted]] > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >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. -- Sent from my phone. Please excuse my brevity. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] subsetting ls() as per class...
Looking at ?rm, my solution would be something like rm(list = grep("\\.NS$", ls(), value = TRUE)) But test it since I have not tested it. Peter On Fri, Jul 27, 2018 at 10:58 PM akshay kulkarni wrote: > > dear memebers, >I am using R in AWS linux instance for my > research. I want to remove certain objects from the global environment to > reduce my EBS cost..for example, I want to remove all objects of class "xts", > "zoo". Is there any way to automate this, instead of removing the objects one > by one? > > Basically, I want to subset ls() according to class, and then remove that > subset by using rm function. > > I got to know about mget in SO, but that is not working in my case > > Also, all the above objects end with ".NS". I came to know that you can > remove objects starting with a certain pattern; is there any way to remove > objects ending in a certain pattern? > > very many thanks for your time and effort... > yours sincerely, > AKSHAY M KULKARNI > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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 -- To UNSUBSCRIBE and more, see 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] subsetting ls() as per class...
dear memebers, I am using R in AWS linux instance for my research. I want to remove certain objects from the global environment to reduce my EBS cost..for example, I want to remove all objects of class "xts", "zoo". Is there any way to automate this, instead of removing the objects one by one? Basically, I want to subset ls() according to class, and then remove that subset by using rm function. I got to know about mget in SO, but that is not working in my case Also, all the above objects end with ".NS". I came to know that you can remove objects starting with a certain pattern; is there any way to remove objects ending in a certain pattern? very many thanks for your time and effort... yours sincerely, AKSHAY M KULKARNI [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.