IPS-LMU / emuR

The main R package for the EMU Speech Database Management System (EMU-SDMS)
http://ips-lmu.github.io/EMU.html
23 stars 15 forks source link

Check for user-defined options on load #240

Closed stefanocoretta closed 3 years ago

stefanocoretta commented 3 years ago

Hi! The current .onLoad function overrides a user-defined emuR.emuWebApp.dir option:

https://github.com/IPS-LMU/emuR/blob/5102bfcb7ee16c2569b4d2e509d43e341586df41/R/zzz.R#L1-L7

The following first checks for user-defined options and changes only non-defined ones (as of now, the functions sets only one option, but maybe in the future there'll be more). Would have done a PR, but for such a tiny change I didn't want to go through the hassle. 😅

.onLoad <- function(libname, pkgname) { 
  op <- options()
  op.emuR <- list(
    emuR.emuWebApp.dir = file.path(tempdir(), "EMU-webApp")
    # emuR.emuWebApp.dir = file.path("~/Developer/EMU-webApp/dist/") # for devel
  )
  # set package options 
  toset <- !(names(op.emuR) %in% names(op))
  if(any(toset)) options(op.emuR[toset])

  invisible() 
 } 
raphywink commented 3 years ago

Thanks for this! Will integrate into next release as I do think it is a cleaner option. However, the only thing that I don't like about such and approach is that users tend to forget what options they have set (e.g. in their .Renv file) and then end up, for example, using a really old version of the EMU-webApp (those are always super fun 2 debug -> 20 emails back and forth be4 u discover: "oh you are not on the current version... why?"). If they have to set the option explicitly at the top of their scripts after library(emuR) it is just more explicit and better documented (doesn't mean that they forget what they where doing there and just hit cmd + enter without looking at what is actually beeing executed)