Is there a way to
- Run a script on package load?
- Within that package, change default function values automatically?
For example, have R
detect whether you are using Windows, or Mac. Then R would change some default function input values.
Is there a way to
For example, have R
detect whether you are using Windows, or Mac. Then R would change some default function input values.
Thank you all for the great guidance. Following this post, and this post, i was able to come up with this answer. Note, for this to work you need to assign these values to the .GlobaEnv
using the <<-
.
formals
returns the function input names and values. Here I show how to change the defaults values of these different functions
# This will run on starup, detect your device,
# and then change different function default values.
.onLoad <- function(libname, pkgname){
# First detect what the system is
# If it is not on windows change default values
# of function that require changes.
systemType <- Sys.info()[1]
if( systemType != "Windows" ){
formals(tcd)$info <<- F
formals(tcd)$bcex <<- 0.5
windows <<- cairoDevice::Cairo
formals(windows)$pointsize <<- 7
formals(PeakFunc7)$bcex <<- 1.5
formals(RDView)$wh <<- 11
formals(RDView)$hh <<- 6
}
}