0

I've looked at the function installed.packages and was wondering if there was a way to do something similar for a package. Specifically, how can I best extract certain "functions" from a pacakge. This is probably best explained using the sample code below:

get("Species",as.environment(iris))

The above helps me obtain the Species column from iris. Logically, I thought of something like this:

g<-library(ggplot2)
get("theme_",as.environment(g))

This returns the following error:

Error in as.environment(g) : no item called "forcats" on the search list

How can I best achieve what I'm trying to do? Thanks!

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
  • 1
    Related: [Seeking Functions in a Package](https://stackoverflow.com/questions/20535247/seeking-functions-in-a-package) – Henrik Feb 01 '19 at 17:09

1 Answers1

2

You can use the function lsf.str to list what you want. Also you can use the argument pattern to filter the pattern that you want:

themes <- lsf.str("package:ggplot2", pattern = "theme_")
paste(themes)
> paste(themes)
 [1] "theme_bw"       "theme_classic"  "theme_dark"     "theme_get"      "theme_gray"     "theme_grey"     "theme_light"    "theme_linedraw" "theme_minimal"  "theme_replace" 
[11] "theme_set"      "theme_test"     "theme_update"   "theme_void" 
Douglas Mesquita
  • 1,011
  • 7
  • 12