What is the ls.str() function in R?
Overview
The ls.str() function in R is used to return a list of objects and their structure.
Syntax
ls.str(pos = -1, name, envir, all.names = FALSE,pattern, mode = "any")
Parameter values
The ls.str() function takes the following optional parameter values:
pos: This is an integer value that represents thesearchpath position or-1, indicating the current environment.name: This is a name that represents thesearchpath position.envir: This represents the environment that is to be used.all.names: This takes a logical value (TRUEorFALSE) 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 themodeof objects that are to be considered.
Code
# 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")
Explanation
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 (.).