[R] Variable scoping question

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Thu Sep 8 17:32:42 CEST 2011


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of jim holtman
> Sent: Thursday, September 08, 2011 6:52 AM
> To: Bos, Roger
> Cc: r-help at r-project.org
> Subject: Re: [R] Variable scoping question
> 
> Here is a function I use to look at the sizes of objects:
> 
> my.ls <-
> function (pos = 1, sorted = FALSE)
> {
>     .result <- sapply(ls(pos = pos, all.names = TRUE), function(..x)
> object.size(eval(as.symbol(..x))))
>     if (sorted) {
>         .result <- rev(sort(.result))
>     }
>     .ls <- as.data.frame(rbind(as.matrix(.result), `**Total` =
> sum(.result)))
>     names(.ls) <- "Size"
>     .ls$Size <- formatC(.ls$Size, big.mark = ",", digits = 0,
>         format = "f")
>     .ls$Mode <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)], function(x)
> mode(eval(as.symbol(x))))),
>         "-------")
>     .ls
> }
> 

Jim,

I thought I would try out your function above.  I copy-and-pasted the function into a newly started, vanilla R session, then ran the following code. 

> x <- 1:1000
> my.ls()
          Size      Mode
my.ls   12,576  function
x        4,040 character
**Total 16,616   -------
>

I don't understand the character mode for the vector x.  Any thoughts?  Here is my sessionInfo().

> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_2.13.1
>


Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204




More information about the R-help mailing list