You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am a bit at a loss.
I am developing a package that requires RBioFormats::read.image() to lead subsections of images. THus, I need to spin up a java VM prior to loading these functions, and given that the images are 4000x6000 pixels large the default heap size fits not suffice.
My thoughts were that using .onLoad() I could successfully apply -Xmx8g.
zzz.R:
..onLoad<-function(lib, pkg) {
curr_memory<- getOption("java.parameters")
options(dfl.java_parameters=curr_memory)
GB<-8if (is.null(curr_memory)) {
options(java.parameters= paste0("-Xmx",GB,"g"))
packageStartupMessage(paste0("1Set option <java.parameters> to '",getOption("java.parameters"),"'"))
} else {
matches<- regexec("(\\d+)(.*)", curr_memory)
value<- as.integer(regmatches(curr_memory, matches)[[1]][[2]])
unit<- regmatches(curr_memory, matches)[[1]][[3]]
if (isFALSE(unit=="g")) { # we loaded less than a gigabyte - so we must stock up
options(java.parameters= paste0("-Xmx",GB,"g"))
packageStartupMessage(paste0("2Set option <java.parameters> to '",getOption("java.parameters"),"'"))
} else {
if (value<GB) {
options(java.parameters= paste0("-Xmx",GB,"g"))
packageStartupMessage(paste0("3Set option <java.parameters> to '",getOption("java.parameters"),"'"))
} else {
packageStartupMessage(paste0("4<java.parameters> is already set to '",getOption("java.parameters"),"'"))
}
}
}
invisible()
}
.onUnLoad<-function(lib, pkg) {
## reset Java parameters
options(java.parameters= getOption("dfl.java_parameters"))
options(dfl.java_parameters=NULL)
}
The NAMESPACE:
# Generated by roxygen2: do not edit by hand
export(load_image)
export(prep_loading)
importFrom(RBioFormats,coreMetadata)
importFrom(RBioFormats,read.image)
importFrom(RBioFormats,read.metadata)
importFrom(imager,RGBtoHSV)
importFrom(imager,as.cimg)
importFrom(imager,load.image)
importFrom(imager,sRGBtoRGB)
importFrom(stringr,str_c)
But this approach very reliably does nothing. Executing
I want my package to ensure that RBioFormats gets loaded with 8 GB.
How can I do so automatically? What am I not understanding here?
Thank you,
Sincerely,
~Gw
The text was updated successfully, but these errors were encountered:
Gewerd-Strauss
changed the title
Package development depending on RBioFormats: How can I reliably set java.parameters when importing functions from RBioFormats?
Package development depending on RBioFormats: How can I reliably set java.parameters when importing functions from RBioFormats into my package?
Mar 12, 2024
Hello,
I am a bit at a loss.
I am developing a package that requires
RBioFormats::read.image()
to lead subsections of images. THus, I need to spin up a java VM prior to loading these functions, and given that the images are 4000x6000 pixels large the default heap size fits not suffice.In normal scripts, you could ensure
My thoughts were that using
.onLoad()
I could successfully apply-Xmx8g
.zzz.R
:The NAMESPACE:
But this approach very reliably does nothing. Executing
after either calling
library(my_package)
or executingdevtools::load_all(".")
however still returns:Functions which require
RBioFormats
access its functions viaI want my package to ensure that RBioFormats gets loaded with 8 GB.
How can I do so automatically? What am I not understanding here?
Thank you,
Sincerely,
~Gw
The text was updated successfully, but these errors were encountered: