[R] stupid R tricks
dwinsemius at comcast.net
Sun Nov 7 18:25:06 CET 2010
On Nov 7, 2010, at 11:40 AM, Carl Witthoft wrote:
> Hi all,
> Just thought I'd post this (maybe) helpful tool I wrote. For people
> like me who are bad at keeping a clean environment, it's a time-saver.
> #simple command to get only one type of object in current environment
> if (type=='function') type <-'closure'
As a fellow messy-enviromnetalist that was useful. Here's a similar
function that returns a vector of object names belonging to a
particular (single) class:
> getclass <- function(cls) ls(envir=.GlobalEnv)[
class(eval(parse(text=x))) ) == cls
 "d" "df" "set1HLI"
 "capture.ps" "getclass" "getsizes" "getweek"
 "maintainer" "myfunction" "rd.txt" "rhelpSearch"
It is not designed to identify multi-class objects, so it would miss a
class of "lm" if there were 2 members in a class vector.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help