addinit icon indicating copy to clipboard operation
addinit copied to clipboard

installed packages not found when setting some options in .Rprofile

Open verajosemanuel opened this issue 5 years ago • 6 comments

Double checked which .Rprofile is loading to be sure. Using the example from documentation:

my_custom_params <- list(
  author = "Victor",
  project = list(
    folders = list(
      default = c("R", "inst", "man", "data-raw", "data", "tests"),
      selected = c("R", "man")
    ),
    packages = list(
      default = rownames(installed.packages()),
      selected = "shiny"
    )
  )
)
options("addinit" = my_custom_params)

an error is shown:

Error in installed.packages() : 
  "installed.packages" not found

verajosemanuel avatar Aug 21 '19 08:08 verajosemanuel

Hi Jose,

Apparently you have to use the namespace of the function utils::installed.packages (although it is a function from base R). With your previous list of directories, the display may not be optimal, tell me if you want I look into that.

Victor

pvictor avatar Aug 21 '19 08:08 pvictor

thanks for your quick response.

setting the commad to utils::installed.packages crashed Rstudio with a nasty message (mac OS):

The R session had a fatal error.

ERROR r error 4 (R code execution error) [errormsg=Error: option error has NULL value ]; OCCURRED AT: rstudio::core::Error rstudio::r::exec::executeSafely(boost::function<void ()>) /Users/vagrant/workspace/IDE/macos-v1.2/src/cpp/r/RExec.cpp:224

Here my script:



my_custom_params <- list(
  author = "jm",
  project = list(
    folders = list(
      default = c("src", "data", "output", "data/raw", "data/temp", "output/plots", "output/reports", "output/data"),
      selected = c("src", "data", "output", "data/raw", "data/temp", "output/plots", "output/reports", "output/data")
    ),
    packages = list(
      default = rownames(utils::installed.packages()),
      selected = "tidyverse"
    )
  )
)
options("addinit" = my_custom_params)

verajosemanuel avatar Aug 21 '19 09:08 verajosemanuel

With your previous list of directories, the display may not be optimal, tell me if you want I look into that.

Yes, that would be good to be aligned in two or more lines to better layout

verajosemanuel avatar Aug 21 '19 09:08 verajosemanuel

This is a weird error!

Not a real answer, but you can skip the line with default = rownames(utils::installed.packages()),, e.g. :

my_custom_params <- list(
  author = "jm",
  project = list(
    folders = list(
      default = c("src", "data", "output", "data/raw", "data/temp", "output/plots", "output/reports", "output/data"),
      selected = c("src", "data", "output", "data/raw", "data/temp", "output/plots", "output/reports", "output/data")
    ),
    packages = list(
      selected = "tidyverse"
    )
  )
)
options("addinit" = my_custom_params)

I'll think about how to better manage the display

pvictor avatar Aug 21 '19 09:08 pvictor

I'll think about how to better manage the display

Thanks a lot, I think this is a great addin to accelerate coding workflow!

verajosemanuel avatar Aug 21 '19 10:08 verajosemanuel

Apparently you have to use the namespace of the function utils::installed.packages

Mac OS here. Add same problem and this did solve it. Thanks for your great AddInn package

hseverac avatar Feb 04 '23 18:02 hseverac