noaa-onms / cinms

Channel Islands National Marine Sanctuary
https://noaa-onms.github.io/cinms
MIT License
3 stars 1 forks source link

trouble with installing nms4r #55

Closed superjai closed 3 years ago

superjai commented 3 years ago

So @bbest I am having a strange problem with nms4r. As you know, I have pointed all of the rmd modal files to nms4r to grab functions (instead of going to utility.r, etc.). I edited the initial r chunk of the rmd files in the modals folder to contain this:

library(devtools)
devtools::install_github("marinebon/nms4r")

This worked just fine for knitting single rmd files. The issue I am having comes up when rendering all of the rmd files at once. I created a function to do that in nms4r - render_modal_windows. This function renders all rmd files in the folder modals, adding in the tooltips (handling rmd files with interactive graphs differently than rmd files without them).

For some reason, in this circumstance, nms4r seems to get pulled from github for every single render. Which it shouldn't be doing, but it nonetheless does do. This causes github to raise a flag as github only allows 60 unauthenticated requests per hour per ip address.

So, as a work around, I edited the initial code chunk of the rmd files in the modal folder to only install nms4r if it isn't there already, as follows:

ip = installed.packages()[,1]
if (all(ip!="nms4r")){
  library(devtools)
  devtools::install_github("marinebon/nms4r")
}

This is rather crude, as it won't install nms4r if a new version of the package is available - it just checks to see if nms4r is there at all. Unfortunately, I have checked devtools, githubinstall, and other r packages that install directly from github - I can't seem to find a way to check version numbers of r packages hosted on github.

Anyway, that's the issue. It isn't the end of the world, but is annoying.

bbest commented 3 years ago

Based on the package development cheatsheet:

image

We do not want to re-install the package each time. just load the library:

# OLD
devtools::install_github("marinebon/nms4r")
# NEW
library(nms4r)

So that means swapping this out in all the modals/*.Rmd.