pacificclimate/Rudunits2

UDUNITS2_XML_PATH is ignored

Opened this issue · 1 comments

R/windows/load.R contains an .onLoad function which unconditionally sets the UDUNITS2_XML_PATH environment variable, so ignores any user specified value. I don't know why this was done, and I don't know whether it's specific to Windows (as suggested by the directory name), but it makes it difficult to specify a database with custom units.

Workaround:

# Load but don't attach library
loadNamespace("udunits2")
Sys.setenv(UDUNITS2_XML_PATH = "udunits/udunits2.xml")
# Attach library, read database using new value of UDUNITS2_XML_PATH
library(udunits2)

I am having the same issue. The following runs perfectly on macOS but fails on Windows, and having to call library() is not an option for package development.

p0 <- "path_to_modified_udunits2.xml"
Sys.setenv(UDUNITS2_XML_PATH = p0)
udunits2:::.onLoad(dirname(system.file(package = "udunits2")), "udunits2")
Sys.getenv("UDUNITS2_XML_PATH") == p0