简体   繁体   中英

How to view internal variables of an R package within an R session?

How can I view all the hidden/internal variables of an R package within an R session?

By hidden/internal variables I mean the sort of variables described in R Packages - External Data which would be stored in the "/pkg/R/sysdata.Rda" file of a package's source code.

My attempts below. None of these are quite right. I feel like I'm missing something. There has to be a straightforward way to do this, right?

Download source

Of course, I can download the package source and

load(file.path("pkg","R","sysdata.Rda"))

But that would involve work outside my session, which doesn't work for me.

Use RStudio's code completion and :::

Within an RStudio R session, I could do

> library(pkg)
> pkg:::

where RStudio auto-suggests what to include after the ::: . Among the suggestions, it shows all internal variables. This is a decent hack. But I'd like something a little cleaner, which doesn't depend on RStudio's auto-suggestions.

Load .rdx and .rdb files?

I noticed

pkg/R/sysdata.rdx
pkg/R/sysdata.rdb

in the package binaries. I thought I might be able to read these to display all the internal variables. How to open .rdb file using R has an answer which relies on lazyLoad . But I wasn't able to get this working. And it seems others weren't either.

You can get all of the functions (exported and unexported) with ls and asNamespace :

head(ls(envir = asNamespace('data.table')))
# [1] "-.IDate"        ":="             "[.data.table"   "[.ITime"       
# [5] "[<-.data.table" "[<-.IDate" 

I'm not positive about your latter point, but I thing system.file has what you want. IIRC anything else that gets installed with the package should be in this location.

head(list.files(system.file(package = 'data.table'), recursive = TRUE))
# [1] "DESCRIPTION" "help"        "html"        "INDEX"       "libs"       
# [6] "LICENSE"   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM