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)

Arguments

x

Object to inspect

expand

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.

max_depth

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

Details

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()

Examples

x <- list(
  TRUE,
  1L,
  runif(100),
  "3"
)
sxp(x)
#> [1:0x5564f0257818] <VECSXP[4]> (named:4)
#>   [2:0x5564ef80fd88] <LGLSXP[1]> (named:10)
#>   [3:0x5564ef80fff0] <INTSXP[1]> (named:8)
#>   [4:0x5564f039efa0] <REALSXP[100]> (named:1)
#>   [5:0x5564ef80c8c0] <STRSXP[1]> (named:4)

# Expand "character" to see underlying CHARSXP entries in the global
# string pool
x <- c("banana", "banana", "apple", "banana")
sxp(x)
#> [1:0x5564ef818a38] <STRSXP[4]> (named:4)
sxp(x, expand = "character")
#> [1:0x5564ef818a38] <STRSXP[4]> (named:4)
#>   [2:0x5564f0ecd1a0] <CHARSXP> (named:13)
#>   [2:0x5564f0ecd1a0]
#>   [3:0x5564f0ecd0f8] <CHARSXP> (named:5)
#>   [2:0x5564f0ecd1a0]

# Expand altrep to see underlying data
x <- 1:10
sxp(x)
#> [1:0x5564ee80edf8] <INTSXP[10]> (altrep named:65535)
sxp(x, expand = "altrep")
#> [1:0x5564ee80edf8] <INTSXP[10]> (altrep named:65535)
#>   _class [2:0x5564e998caf0] <RAWSXP[144]> (named:7999)
#>     _attrib [3:0x5564e99c2078] <LISTSXP> (named:1)
#>       [4:0x5564e99c22a8] <SYMSXP: compact_intseq> (named:38)
#>       [5:0x5564e998dbc0] <SYMSXP: base> (named:65535)
#>       [6:0x5564e99c0a50] <INTSXP[1]> (named:2)
#>   _data1 [7:0x5564ef7e5928] <REALSXP[3]> (named:1)
#>   _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:0x5564ee2bd198] <ENVSXP> (named:5)
#>   x [2:0x5564ee1d7088] <INTSXP[10]> (altrep named:65535)
#>   _enclos [3:0x5564e998eec8] <ENVSXP: empty> (named:65535)
sxp(e1, expand = "environment")
#> [1:0x5564ee2bd198] <ENVSXP> (named:6)
#>   _frame [2:0x5564ee1d76a8] <LISTSXP> (named:1)
#>     x [3:0x5564ee1d7088] <INTSXP[10]> (altrep named:65535)
#>   _hashtab <NILSXP>
#>   _enclos [5:0x5564e998eec8] <ENVSXP: empty> (named:65535)
sxp(e2, expand = "environment")
#> [1:0x5564ee249498] <ENVSXP> (named:5)
#>   _frame <NILSXP>
#>   _hashtab [3:0x5564f02d9fc8] <VECSXP[3/1]> (named:1)
#>     [4:0x5564ee1d7398] <LISTSXP> (named:1)
#>       x [5:0x5564ee1d7088] <INTSXP[10]> (altrep named:65535)
#>     <NILSXP>
#>     <NILSXP>
#>   _enclos [6:0x5564e998eec8] <ENVSXP: empty> (named:65535)