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")
Syntax for the ls.str() function in R

Parameter values

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.

Code

# creating R objects
a <- 42
b <-'foo'
c <- function(x) x^2
.d <- 4 + 5 * 3
# getting the list of all objects and their structures
ls.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 (.).

Free Resources