Why doesn't ls () in R display global variables?

In the code below, LETTERS and letters are global or in the global search path and are accessible through another package (same thing!)

> LETTERS
 [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P "" Q "" R "" S "
[20] "T" "U" "V" "W" "X" "Y" "Z"
> letters
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p "" q "" r "" s "
[20] "t" "u" "v" "w" "x" "y" "z"
> ls ()
character (0)
> a <- "1 2 3"
> ls ()
[1] "a"
> rm (a)
> ls ()
character (0)
> 

+5
source share
5 answers

For the same reason, it does not list all exported functions in all attached packages (from ?ls):

The default call environment is 'ls' or 'objects'.

, LETTERS ls, .

# LETTERS is in there somewhere...
sapply(search(),ls)
+11

?LETTERS, , , . , base. , ls(), :

> ls(name = "package:base", pattern = "LETTERS")
[1] "LETTERS"
> ls(name = "package:base", pattern = "letters")
[1] "letters"
+7
apropos("letters",where=TRUE)
        9         9 
"letters" "LETTERS" 

, 9 ,

search()
[1] ".GlobalEnv"        "package:stats"     "package:graphics" 
[4] "package:grDevices" "package:utils"     "package:datasets" 
[7] "package:methods"   "Autoloads"         "package:base"

base.

+6

, apropos. - , , , 30. , . , "", "" .

apropos(what="^", mode="character")
 [1] ".Depends"             ".Depends"             ".Depends"             ".Depends"            
 [5] ".Depends"             ".Depends"             ".Depends"             ".Depends"            
 [9] ".Depends"             ".Depends"             ".Depends"             ".Depends"            
[13] ".Device"              ".Firstlib_as_onLoad"  ".knownS3Generics"     ".Library"            
[17] ".Library.site"        ".S3PrimitiveGenerics" "blues9"               "letters"             
[21] "LETTERS"              "month.abb"            "month.name"           "p.adjust.methods"    
[25] "R.version.string"     "sas.get.macro"        "state.abb"            "state.name"          
[29] "tm"   

, ".Depends". , "pi" , . "pi" , 25, , search():

> search()[as.numeric(names(apropos(what="^pi", mode="numeric",where=1)))]
[1] "package:base"
# Removing the numeric restriction
> search()[as.numeric(names(apropos(what="^pi",where=1)))]
 [1] "package:base"      "package:utils"     "package:lubridate" "package:grDevices" "package:graphics" 
 [6] "package:graphics"  "package:MASS"      "package:MASS"      "package:MASS"      "package:base"     

, ( ), "pi" . , "base" .

+6

. , :

R> myLETTERS <- LETTERS
R> ls()
[1] "myLETTERS"
R> 

R> data()

. . help(data), , , .

+3

All Articles