Closed 12devsilva12 closed 1 year ago
Bumping this question, running into the same issue despite having docker installed? Can anyone please help!
@hol430 wrote the Croptimizr module but he has now left us to work elsewhere. I'm not familiar with it at all. I could probably figure it out by looking at the source code but it would take time that I don't have at the moment. Sorry.
Same errors occur under linux. Looks to be that the container doesnt contain the stics package. It is being updated (last was 7 days ago) but I dont know where to look for the container build logs, sorry
The apsim docker image uses an old version of R (4.1.2), which will no longer build the Stics package:
* building 'CroptimizR_0.5.1.tar.gz'
...
ERROR: dependencies 'BayesianTools', 'nloptr' are not available for package 'CroptimizR'
I don't get this error on 4.2.2
This appears to be because the apsimng-r image (which is used as a layer in apsimng-complete) hasnt been rebuilt for some time. @hol353 - I suspect the jenkins trigger needs to be changed/pulled/whatever here.
As a workaround, if you set the environment variable "APSIM_NO_DOCKER" to 1, (eg set the variable in a command window, and start ApsimNG.exe within that window) it will attempt to use your native (4.22?) installation of R instead of the docker image
Hmm I don't know if it is related but our build system is giving this error about R and croptimizr:
System.Exception: Error from R:
Script path: '/tmp/fdc73a03-c879-4c40-ab1f-9ab08d64a7e9-getPackage.R'
StdErr:
Warning in install.packages(pkg, repos = "https://cran.csiro.au/", lib = pkgpath, :
'lib = "ApsimInitiative/ApsimX/rpackages"' is not writable
Error in install.packages(pkg, repos = "https://cran.csiro.au/", lib = pkgpath, :
unable to install packages
Calls: getPackage -> install.packages
In addition: Warning message:
In dir.create(pkgpath) :
cannot create dir 'ApsimInitiative/ApsimX/rpackages', reason 'No such file or directory'
Execution halted
StdOut:
Script contents:
#' Loads a package, installing it if necessary.
#'
#' @param pkg Name of the package to be installed/loaded.
#' @param pkgpath Path where package is to be installed.
#' @return Nothing.
getPackage <- function(pkg, pkgpath) {
if (!pkg %in% rownames(installed.packages())) {
if (!dir.exists(pkgpath)) {
dir.create(pkgpath)
}
install.packages(pkg, repos = "https://cran.csiro.au/", lib = pkgpath, dependencies = TRUE)
} else {
print(paste('Package', pkg, 'is already installed.'))
}
}
args = commandArgs(TRUE)
getPackage(args[1], args[2])
at Models.Utilities.R.Run(String fileName, Boolean throwOnError, String[] arguments) in /tmp/ApsimX/Models/Utilities/R.cs:line 194
at Models.Utilities.R.InstallPackage(String package) in /tmp/ApsimX/Models/Utilities/R.cs:line 265
at Models.Utilities.R.InstallPackages(String[] packages) in /tmp/ApsimX/Models/Utilities/R.cs:line 307
at Models.Optimisation.CroptimizR.Run(CancellationTokenSource cancelToken) in /tmp/ApsimX/Models/Optimisation/CroptimizR.cs:line 497
at APSIM.Shared.JobRunning.JobRunner.Run(IRunnable job) in /tmp/ApsimX/APSIM.Shared/JobRunning/JobRunner.cs:line 225
at APSIM.Shared.JobRunning.JobRunner.RunActualJob(IRunnable job, IJobManager jobManager) in /tmp/ApsimX/APSIM.Shared/JobRunning/JobRunner.cs:line 189
CroptimizR has finished. Elapsed time was 3.7 seconds.
I've updated the APSIM R docker container to use R 4.2.2 and @hol430 added a missing bayesean R package. Does it work now?
The example works on linux now. @12devsilva12 can you please check on your windows system, and close the issue if done
Not sure if this helps but there is related documentation page located here: https://apsimnextgeneration.netlify.app/usage/croptimizr/
Using the instructions above, I was able to run the comptimizr example with no errors. Closing this.
I am trying to work through the Optimization Example included in APSIMX. I have Docker running locally, but not sure what setup is required. I have installed CroptimizR from RStudio. I am getting the following error when I try to run the example:
Any advice?