R Under development (unstable) (2026-06-25 r90191 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## Testing the compare_apsim function > require(apsimx) Loading required package: apsimx APSIM(X) not found. If APSIM(X) is installed in an alternative location, set paths manually using 'apsimx_options' or 'apsim_options'. You can still try as the package will look into the registry (under Windows) > packageVersion("apsimx") [1] '2.8.270' > require(ggplot2) Loading required package: ggplot2 > apsimx_options(warn.versions = FALSE) > > run.test.compare.apsimx <- get(".run.local.tests", envir = apsimx.options) > > extd.dir <- system.file("extdata", package = "apsimx") > > if(run.test.compare.apsimx){ + + data(obsWheat) + sim.opt <- read.csv(file.path(extd.dir, "wheat-sim-opt.csv")) + sim.opt$Date <- as.Date(sim.opt$Date) + + ## Testing compare_apsim + cap <- compare_apsim(obsWheat, sim.opt, labels = c("obs", "sim")) + + compare_apsim(obsWheat, sim.opt, labels = c("obs", "sim"), verbose = TRUE) + + plot(cap) + plot(cap, plot.type = "diff") + plot(cap, plot.type = "ts") + + plot(cap, variable = "AboveGround") + plot(cap, variable = "AboveGround", plot.type = "diff") + plot(cap, variable = "AboveGround", plot.type = "resid") + plot(cap, variable = "AboveGround", plot.type = "ts") + + ## Testing the id functionality ---- + plot(cap, variable = "AboveGround", plot.type = "resid", id = 0.05) + plot(cap, variable = "AboveGround", plot.type = "resid", id = 0.05, + id.label = letters[1:10]) + plot(cap, variable = "AboveGround", plot.type = "ts", id = 0.05) + plot(cap, variable = "AboveGround", plot.type = "ts", id = 0.05, + id.label = letters[1:10]) + + ## Adding the capability when the length of the index is equal to 2 + user.name <- Sys.info()[["user"]] + + if(user.name == "femiguez"){ + root.dir <- "C:/Users/femiguez/Dropbox/apsimx-other/pheno_optim" + }else{ + if(user.name == "fernandomiguez"){ + root.dir <- "~/Dropbox/apsimx-other/pheno_optim/" + }else{ + stop("This test should only run in local computers") + } + } + + obsPheno <- read.csv(file.path(root.dir, "obsPheno.csv")) + simPheno <- read.csv(file.path(root.dir, "simPheno.csv")) + + obsPheno$Date <- as.Date(obsPheno$Date) + simPheno$Date <- as.Date(simPheno$Date) + + cmp <- compare_apsim(obsPheno, simPheno, index = c("report", "Date"), labels = c("Obs", "Sim")) + + plot(cmp) + plot(cmp, by = "report") + plot(cmp, by = "report", se = FALSE) + plot(cmp, by = "report", se = FALSE, facet = TRUE) + plot(cmp, by = "report", plot.type = "ts", facet = TRUE, se = FALSE) + + plot(cmp, by = "report", plot.type = "ts", facet = TRUE, se = FALSE) + + ggplot2::theme(legend.position = "top") + + ### Testing id feature ---- + plot(cmp, by = "report", se = FALSE, id = 0.05, facet = TRUE, + id.label = obsPheno$Date) + + } > > if(FALSE){ + + ### This test is not fully developed + if(user.name == "femiguez"){ + root.dir <- "C:/Users/femiguez/Dropbox" + }else{ + root.dir <- "~/Dropbox" + } + + ### Testing inspired by a more complicated dataset? + sim.wheat <- read_apsim_all(src.dir = file.path(root.dir, "apsimx-other/KeLiu/mcmc_test/mcmc_test")) + sim.wheat$outfile <- as.factor(sim.wheat$outfile) + ## obs.wheat <- as.data.frame(readxl::read_excel("~/Dropbox/apsimx-other/KeLiu/mcmc_test/mcmc_test/Obs.xlsx")) + obs.wheat$outfile <- as.factor(obs.wheat$outfile) + obs.wheat$Date <- as.Date(obs.wheat$Date) + + cmp1 <- compare_apsim(obs.wheat, sim.wheat, + labels = c("obs", "sim")) + + cmp1 <- compare_apsim(obs.wheat, sim.wheat, index = c("outfile", "Date"), + labels = c("obs", "sim")) + + plot(cmp1) + plot(cmp1, by = "outfile") + plot(cmp1, by = "outfile", se = FALSE) + plot(cmp1, by = "outfile", plot.type = "ts", facet = TRUE, se = FALSE) + + } > > proc.time() user system elapsed 1.06 0.28 1.34