0

In the package that I wrote, in the description file, here are some of the imports:

Imports: jsonlite,
    tibble,
    shiny,
    ggplot2,
    plotly (>= 4.5.6.9000),
    dplyr,
    purrr,
    lubridate

But when I load my package like this:

devtools::load_all()

only some of those packages above get attached to the workspace. For example, dplyr was attached, but plotly was not.

What determines what packages in the "import" statement of the description file get loaded to the workspace when "my_package" gets loaded

  • Did you have `dplyr` loaded before you loaded your package? I'm guessing it was loaded before. The `Imports` section shouldn't attach anything, the `Depends` section will. See https://stackoverflow.com/questions/8637993/better-explanation-of-when-to-use-imports-depends. – MrFlick Jan 10 '19 at 19:31
  • @MrFlick nope, my Rstudio session is fresh. – Bear Bile Farming is Torture Jan 10 '19 at 19:40
  • But do you have Rstudio automatically load the package for you on startup? Before you run `library(my_package)`, check your `sessionInfo()`. Does your package have an `onLoad` function? – MrFlick Jan 10 '19 at 19:41
  • @MrFlick I word searched my_package and "onLoad" does not show up. sessionInfo() show that only stats, graphics, grDevices, utils, datasets, methods base packages were attached before library(my_package). Actually, currently I'm just running this "devtools::load_all()" in order to load my package that is underdevelopment. Not sure if this is causing it to load those extra packages. But it shouldn't. According to the documentation, "devtools::load_all()" is supposed to simulate "library(my_package)" – Bear Bile Farming is Torture Jan 10 '19 at 19:49
  • You've got a possible answer to your question. It's polite on this site to mark it as "accepted" (you'll see how if you look), or leave comments explaining why it doesn't meet your needs. – user2554330 Jan 11 '19 at 16:40

1 Answers1

0

There's a difference between being "loaded" and being "attached". Being loaded means that the package is in memory, so functions in your package can call functions in it. Being attached means it is on the search list, so the user can call functions in it.

If a package is attached it has to be loaded as well, but packages can be loaded without showing up in the search list.

If you use the double colon notation like purrr::map, then R will check if purrr is loaded, and load it if not, but it won't add it to the search list. It won't need to be loaded the second time you make a call like that, because packages normally stay loaded once they are loaded once.

user2554330
  • 37,248
  • 4
  • 43
  • 90