Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To see All the content (not just objects) in a package in R

Tags:

r

This is likely a newbie's question but I think I did my homework and yet have not found the answer (I hope to find) so I am posting it here to seek some assistance.

Similar questions were asked before but from what I found, no answer could help me with the current issue except an "expensive" solution, which requires an editor for R.

I learned that ls and objects allow us to view the objects inside a package. But even with ls(all.names=TRUE), I still couldn't see all the content. Someone suggested ls(getNAMEspace) but still this isn't "good" enough for me.

e.g.

>search()
[1]".GlobalEvn"      "package:TCGAGBM"
>ls("package:TCGAGBM")
character(0)
>ls(getNamespace("TCGAGBM"),all.names=TRUE)
[1]"._NAMESPACE_."   "._S3MethodsTable_."  ".packageName"

However, under C (cmd), I see the following

C:\Users\XYZ\Documents\R\R-2.15.1\library\TCGAGBM . .. data extdata ...... (total 3 File(s), 7 Dir(s))

I came across this "discrepancy" when I saw the following line of script -

>clinical=read.delim(system.file(
+"extdata/Clinical/clinical_patient_public_GBM.txt.gz",
+package="TCGAGBM"), header=TRUE)

Thus I was wondering if there is a way under R to see ALL the content within a package so that we could "know" how better to utilize the package. Vignette would probably help, but in my limited experience with R so far, I have found that some packages did not come with Vignette.

Any comment will be appreciated to help me learn more about R.

like image 327
B Chen Avatar asked Sep 25 '12 01:09

B Chen


3 Answers

My preferred approach by far is to simply look at the source code of a package in question.

In fact, I actually do that pretty often as running CRANberries creates a local CRAN mirror as a side effect. But even if you don't, CRAN packages really are only a quick download away and will come with comments in the source which the parsed code excludes.

Edit: I just found what Ben found too: Sean Davis' page at http://watson.nci.nih.gov/~sdavis/tutorials/TCGA_data_integration/ -- looks like it uses some BioC packages too. I would still study the source which often has more comments, annotations, extras, ... than the installed package. But maybe that's just my preference. YMMV as they say.

like image 168
Dirk Eddelbuettel Avatar answered Sep 28 '22 18:09

Dirk Eddelbuettel


Here is another way to explore the functionality of any package. Although it is not as comprehensive a solution as Dirk's, it is still useful. When I want to know all the functionality of a package, I quickly list all of its functions. Then if I'm curious about any function, I an quickly pull up the help file ?function_name and see what it does. For that reason, I keep this function in my .rprofile so it automatically loads every time I run R.

lsp <- function (package, all.names = FALSE, pattern) {
    package <- deparse(substitute(package))
    ls(pos = paste("package", package, sep = ":"), all.names = all.names, 
        pattern = pattern)
}

This is especially helpful when I know the partial name of a function and what package it belongs to but quickly need to find it.

e.g.

> lsp(ggplot2, pattern = "geom")
 [1] "geom_abline"          "geom_area"           
 [3] "geom_bar"             "geom_bin2d"          
 [5] "geom_blank"           "geom_boxplot"        
 [7] "geom_contour"         "geom_crossbar"       
 [9] "geom_density"         "geom_density2d"      
[11] "geom_dotplot"         "geom_errorbar"       
[13] "geom_errorbarh"       "geom_freqpoly"       
[15] "geom_hex"             "geom_histogram"      
[17] "geom_hline"           "geom_jitter"         
[19] "geom_line"            "geom_linerange"      
[21] "geom_map"             "geom_path"           
[23] "geom_point"           "geom_pointrange"     
[25] "geom_polygon"         "geom_quantile"       
[27] "geom_raster"          "geom_rect"           
[29] "geom_ribbon"          "geom_rug"            
[31] "geom_segment"         "geom_smooth"         
[33] "geom_step"            "geom_text"           
[35] "geom_tile"            "geom_violin"         
[37] "geom_vline"           "update_geom_defaults"
like image 24
Maiasaura Avatar answered Sep 28 '22 19:09

Maiasaura


If you want to see all the system files for a particular package, then try something like

list.files(system.file(package = 'TCGAGBM'), recursive = T, full.names = T)

How useful this will be will depend on your OS, as the way packages are installed is OS dependent

see the appropriate section in R Installation and Administration manual for more details.

NOTE

@DirkEddelbuettel's suggestion of inspecting the source is a far better approach.

like image 43
mnel Avatar answered Sep 28 '22 20:09

mnel