ls dan objek mengembalikan vektor string karakter yang memberikan nama objek di lingkungan tertentu. Ketika dipanggil tanpa argumen di prompt tingkat atas, ls menunjukkan kumpulan data dan fungsi apa yang telah ditentukan pengguna. Ketika dipanggil tanpa argumen di dalam suatu fungsi, ls mengembalikan nama variabel lokal fungsi: ini berguna jika digabungkan dengan browser.
ls(name, pos = -1L, envir = as.environment(pos),
all.names = FALSE, pattern, sorted = TRUE)
objects(name, pos= -1L, envir = as.environment(pos),
all.names = FALSE, pattern, sorted = TRUE)
| Parameter | Deskripsi |
|---|---|
name |
which environment to use in listing the available objects. Defaults to the current environment. Although called name for back compatibility, in fact this argument can specify the environment in any form; see the ‘Details’ section. |
pos |
an alternative argument to name for specifying the environment as a position in the search list. Mostly there for back compatibility. |
envir |
an alternative argument to name for specifying the environment. Mostly there for back compatibility. |
all.names |
a logical value. If TRUE, all object names are returned. If FALSE, names which begin with a . are omitted. |
pattern |
an optional regular expression. Only names matching pattern are returned. glob2rx can be used to convert wildcard patterns to regular expressions. |
sorted |
logical indicating if the resulting character should be sorted alphabetically. Note that this is part of ls() may take most of the time. |
# NOT RUN {
.Ob <- 1
ls(pattern = "O")
ls(pattern= "O", all.names = TRUE) # also shows ".[foo]"
# shows an empty list because inside myfunc no variables are defined
myfunc <- function() {ls()}
myfunc()
# define a local variable inside myfunc
myfunc <- function() {y <- 1; ls()}
myfunc() # shows "y"
# }