The ls.str()
function in R is used to return a list of objects and their structure.
ls.str(pos = -1, name, envir, all.names = FALSE,pattern, mode = "any")
The ls.str()
function takes the following optional parameter values:
pos
: This is an integer value that represents the search
path position or -1
, indicating the current environment.
name
: This is a name that represents the search
path position.
envir
: This represents the environment that is to be used.
all.names
: This takes a logical value (TRUE
or FALSE
) that indicates whether the names starting with a dot (.) are omitted or not.
pattern
: This is an expression that is passed to the function in which only the names that match the given expression are considered.
mode
: This is a character that specifies the mode
of objects that are to be considered.
# creating R objectsa <- 42b <-'foo'c <- function(x) x^2.d <- 4 + 5 * 3# getting the list of all objects and their structuresls.str(all.names = "TRUE")
Lines 2–5 : We create different R objects.
Line 8: We use the ls.str()
function to return a list of all the objects in our code and their respective structures, including objects whose names start with a dot (.
).