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

后端 未结 3 612
忘了有多久
忘了有多久 2021-01-04 23:40

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.

相关标签:
3条回答
  • 2021-01-04 23:45

    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"
    
    0 讨论(0)
  • 2021-01-05 00:02

    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.

    0 讨论(0)
  • 2021-01-05 00:03

    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.

    0 讨论(0)
提交回复
热议问题