sxp(x) is similar to .Internal(inspect(x)), recursing into the C data structures underlying any R object. The main difference is the output is a little more compact, it recurses fully, and avoids getting stuck in infinite loops by using a depth-first search. It also returns a list that you can compute with, and carefully uses colour to highlight the most important details.

sxp(x, expand = character(), max_depth = 5L)



Object to inspect


Optionally, expand components of the true that are usually suppressed. Use:

  • "character" to show underlying entries in the global string pool.

  • "environment" to show the underlying hashtables.

  • "altrep" to show the underlying data.

  • "call" to show the full AST (but ast() is usually superior)

  • "bytecode" to show generated bytecode.


Maximum depth to recurse. Use max_depth = Inf (with care!) to recurse as deeply as possible. Skipped elements will be shown as ....`


The name sxp comes from SEXP, the name of the C data structure that underlies all R objects.

See also

Other object inspectors: ast, ref


x <- list( TRUE, 1L, runif(100), "3" ) sxp(x)
#> [1:0x5fccb78] <VECSXP[4]> (named:7) #> [2:0x622ced0] <LGLSXP[1]> (named:7) #> [3:0x622cf08] <INTSXP[1]> (named:7) #> [4:0x6e4dd10] <REALSXP[100]> (named:0) #> [5:0x622cf78] <STRSXP[1]> (named:7)
# Expand "character" to see underlying CHARSXP entries in the global # string pool x <- c("banana", "banana", "apple", "banana") sxp(x)
#> [1:0x741d288] <STRSXP[4]> (named:7)
sxp(x, expand = "character")
#> [1:0x741d288] <STRSXP[4]> (named:7) #> [2:0x622d058] <CHARSXP> (named:0) #> [2:0x622d058] #> [3:0x622d138] <CHARSXP> (named:0) #> [2:0x622d058]
# Expand altrep to see underlying data x <- 1:10 sxp(x)
#> [1:0x54146b8] <INTSXP[10]> (altrep named:7)
sxp(x, expand = "altrep")
#> [1:0x54146b8] <INTSXP[10]> (altrep named:7) #> _class [2:0x1bc5cf0] <RAWSXP[144]> (named:0) #> _attrib [3:0x1bfe5e8] <LISTSXP> (named:0) #> [4:0x1bf6838] <SYMSXP: compact_intseq> (named:0) #> [5:0x1bc91c0] <SYMSXP: base> (named:7) #> [6:0x1bfc000] <INTSXP[1]> (named:0) #> _data1 [7:0x2871f98] <REALSXP[3]> (named:0) #> _data2 <NILSXP>
# Expand environmnets to see the underlying implementation details e1 <- new.env(hash = FALSE, parent = emptyenv(), size = 3L) e2 <- new.env(hash = TRUE, parent = emptyenv(), size = 3L) e1$x <- e2$x <- 1:10 sxp(e1)
#> [1:0x4a0bba0] <ENVSXP> (named:7) #> x [2:0x45d0718] <INTSXP[10]> (altrep named:7) #> _enclos [3:0x1bca3e8] <ENVSXP: empty> (named:7)
sxp(e1, expand = "environment")
#> [1:0x4a0bba0] <ENVSXP> (named:7) #> _frame [2:0x45d0e88] <LISTSXP> (named:0) #> x [3:0x45d0718] <INTSXP[10]> (altrep named:7) #> _hashtab <NILSXP> #> _enclos [5:0x1bca3e8] <ENVSXP: empty> (named:7)
sxp(e2, expand = "environment")
#> [1:0x46400f8] <ENVSXP> (named:7) #> _frame <NILSXP> #> _hashtab [3:0x737a2f8] <VECSXP[3/1]> (named:0) #> [4:0x45d0b78] <LISTSXP> (named:0) #> x [5:0x45d0718] <INTSXP[10]> (altrep named:7) #> <NILSXP> #> <NILSXP> #> _enclos [6:0x1bca3e8] <ENVSXP: empty> (named:7)