Where to load packages when sourcing an R script -
i have 2 r scripts. scriptb called in scripta via source("scriptb.r")
both scripta , scriptb load same library(x)
x knitr
or stringr
or few other packages
however, because scriptb calls library(x)
example, seems scripta forced unload library(x)
, load scriptb library(x)
. leads following error:
error in unloadnamespace(package) : namespace 'x' imported 'y' cannot unloaded error in library(x) : package 'x' version n.nn cannot unloaded
i don't call unloadnamespace in source script i'm not sure why happening? how can prevent unload. should use require()
in scripta can fail gracefully?
so questions are:
is sourcing r script best way include objects r script or there friendlier way
how avoid script trying unload package x?
ok sorted it. problem think was using old versions of stringr in scripta or b updated package , runs fine. suppose r unloads same library if there versioning difference , prefers library called last. that's explanation.
i remain little confused didn't specify version of library when loading , though rstudio keeps 1 version of package.
Comments
Post a Comment