If e is not specified, it will start with environment from which the function was called.

parenvs(e = parent.frame(), all = FALSE)

Arguments

e

An environment or other object.

all

If FALSE (the default), stop at the global environment or the empty environment. If TRUE, print all parents, stopping only at the empty environment (which is the top-level environment).

Examples

# Print the current environment and its parents
parenvs()
#>   label                         name
#> 1 <environment: 0x58b5858b32d0> ""  
#> 2 <environment: 0x58b585a21ef8> ""  
#> 3 <environment: 0x58b586060ea8> ""  
#> 4 <environment: 0x58b57f185250> ""  
#> 5 <environment: R_GlobalEnv>    ""  

# Print the parent environments of the load_all function
e <- parenvs(parenvs)
e
#>   label                         name          
#> 1 <environment: namespace:pryr> ""            
#> 2 <environment: 0x58b57dc807d8> "imports:pryr"
#> 3 <environment: namespace:base> ""            
#> 4 <environment: R_GlobalEnv>    ""            

# Get all parent environments, going all the way to empty env
e <- parenvs(parenvs, TRUE)
e
#>    label                            name               
#> 1  <environment: namespace:pryr>    ""                 
#> 2  <environment: 0x58b57dc807d8>    "imports:pryr"     
#> 3  <environment: namespace:base>    ""                 
#> 4  <environment: R_GlobalEnv>       ""                 
#> 5  <environment: package:stats4>    "package:stats4"   
#> 6  <environment: package:pryr>      "package:pryr"     
#> 7  <environment: package:stats>     "package:stats"    
#> 8  <environment: package:graphics>  "package:graphics" 
#> 9  <environment: package:grDevices> "package:grDevices"
#> 10 <environment: package:utils>     "package:utils"    
#> 11 <environment: package:datasets>  "package:datasets" 
#> 12 <environment: package:methods>   "package:methods"  
#> 13 <environment: 0x58b57b962378>    "Autoloads"        
#> 14 <environment: 0x58b57c87a0f0>    "tools:callr"      
#> 15 <environment: base>              ""                 
#> 16 <environment: R_EmptyEnv>        ""                 

# Print e with paths
print(e, path = TRUE)
#>    label                            name               
#> 1  <environment: namespace:pryr>    ""                 
#> 2  <environment: 0x58b57dc807d8>    "imports:pryr"     
#> 3  <environment: namespace:base>    ""                 
#> 4  <environment: R_GlobalEnv>       ""                 
#> 5  <environment: package:stats4>    "package:stats4"   
#> 6  <environment: package:pryr>      "package:pryr"     
#> 7  <environment: package:stats>     "package:stats"    
#> 8  <environment: package:graphics>  "package:graphics" 
#> 9  <environment: package:grDevices> "package:grDevices"
#> 10 <environment: package:utils>     "package:utils"    
#> 11 <environment: package:datasets>  "package:datasets" 
#> 12 <environment: package:methods>   "package:methods"  
#> 13 <environment: 0x58b57b962378>    "Autoloads"        
#> 14 <environment: 0x58b57c87a0f0>    "tools:callr"      
#> 15 <environment: base>              ""                 
#> 16 <environment: R_EmptyEnv>        ""                 
#>    path                                             
#> 1  ""                                               
#> 2  ""                                               
#> 3  ""                                               
#> 4  ""                                               
#> 5  "/opt/R/4.5.1/lib/R/library/stats4"              
#> 6  "/tmp/Rtmp9GJU8S/temp_libpath3f23a4235f20a1/pryr"
#> 7  "/opt/R/4.5.1/lib/R/library/stats"               
#> 8  "/opt/R/4.5.1/lib/R/library/graphics"            
#> 9  "/opt/R/4.5.1/lib/R/library/grDevices"           
#> 10 "/opt/R/4.5.1/lib/R/library/utils"               
#> 11 "/opt/R/4.5.1/lib/R/library/datasets"            
#> 12 "/opt/R/4.5.1/lib/R/library/methods"             
#> 13 ""                                               
#> 14 ""                                               
#> 15 ""                                               
#> 16 ""                                               

# Print the first 6 environments in the envlist
e[1:6]
#>   label                         name            
#> 1 <environment: namespace:pryr> ""              
#> 2 <environment: 0x58b57dc807d8> "imports:pryr"  
#> 3 <environment: namespace:base> ""              
#> 4 <environment: R_GlobalEnv>    ""              
#> 5 <environment: package:stats4> "package:stats4"
#> 6 <environment: package:pryr>   "package:pryr"  

# Print just the parent environment of load_all.
# This is an envlist with one element.
e[1]
#>   label                         name
#> 1 <environment: namespace:pryr> ""  

# Pull that environment out of the envlist and see what's in it.
e[[1]]
#> <environment: namespace:pryr>
ls(e[[1]], all.names = TRUE)
#>   [1] "%.%"                  "%<a-%"                "%<c-%"               
#>   [4] "%<d-%"                "%||%"                 ".__NAMESPACE__."     
#>   [7] ".__S3MethodsTable__." ".packageName"         "[.envlist"           
#>  [10] "address"              "address2"             "all_named"           
#>  [13] "as.envlist"           "ast"                  "binary2hex"          
#>  [16] "binary_repr"          "bits"                 "bytes"               
#>  [19] "cache"                "call_tree"            "check_name"          
#>  [22] "compact"              "compare_size"         "compose"             
#>  [25] "do_call"              "dots"                 "enclosing_env"       
#>  [28] "eval2"                "explicit"             "explicitDots"        
#>  [31] "explicitPromise"      "f"                    "fget"                
#>  [34] "find_funs"            "find_generic"         "find_uses"           
#>  [37] "ftype"                "fun_args"             "fun_body"            
#>  [40] "fun_calls"            "hex_repr"             "inspect"             
#>  [43] "inspect_"             "internal_generics"    "internal_name"       
#>  [46] "is.formula"           "is_active_binding"    "is_internal"         
#>  [49] "is_internal_generic"  "is_promise"           "is_promise2"         
#>  [52] "is_s3_generic"        "is_s3_method"         "makeExplicit"        
#>  [55] "make_call"            "make_function"        "matched_calls"       
#>  [58] "mem_change"           "mem_used"             "method_from_call"    
#>  [61] "modify_call"          "modify_lang"          "named2"              
#>  [64] "named_dots"           "names_c"              "node_size"           
#>  [67] "object_size"          "otype"                "parent_promise"      
#>  [70] "parenv"               "parenvs"              "partial"             
#>  [73] "partial2"             "primitive_name"       "print.envlist"       
#>  [76] "print.inspect"        "print.inspect_NILSXP" "print.pryr_bytes"    
#>  [79] "promise_code"         "promise_env"          "promise_evaled"      
#>  [82] "promise_info"         "promise_value"        "rebind"              
#>  [85] "refs"                 "rls"                  "sexp_type"           
#>  [88] "show_bytes"           "show_c_source"        "slice"               
#>  [91] "standardise_call"     "stop_list"            "str_trunc"           
#>  [94] "subs"                 "substitute_q"         "terminal_env"        
#>  [97] "to_env"               "track_copy"           "tree"                
#> [100] "typename"             "typename2"            "unenclose"           
#> [103] "uneval"               "where"