R Under development (unstable) (2024-05-04 r86521 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 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. > ## Test reading and writing soils in XML format > ## Author: Fernando E. Miguez > ## Date: 2022-02-16 > ## > ## Required: R package apsimx 2.3.2 > 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) > require(ggplot2) Loading required package: ggplot2 > > apsimx_options(warn.versions = FALSE) > > run.apsimx.soils <- get(".run.local.tests", envir = apsimx.options) > > run.apsimx.soils <- FALSE ## It takes 23 minutes to run the code below > > if(run.apsimx.soils){ + + extd.dir <- system.file("extdata", package = "apsimx") + + sls <- read_apsim_soils("Clarion.soils", src.dir = extd.dir) + + ## All soils in APSoil + apsoil.dir <- "~/Dropbox/apsimx-other/APSoil" + + ## Reading in all this data takes a while + start <- Sys.time() + asls <- read_apsim_soils("APSRU-Australia-soils.soils", src.dir = apsoil.dir) + end <- Sys.time() + + } > > ### Testing fixing a soil profile > > run.apsimx.soils.fix <- get(".run.local.tests", envir = apsimx.options) > > try.isric <- try(get_isric_soil_profile(lonlat = c(-93, 42), fix = TRUE, verbose = FALSE), silent = TRUE) > > ## If the above fails it is very likely that the server is down > if(inherits(try.isric, 'try-error')) run.apsimx.soils.fix <- FALSE > run.apsimx.soils.fix <- FALSE > > if(run.apsimx.soils.fix){ + + tmp.dir <- tempdir() + setwd(tmp.dir) + ex.dir <- auto_detect_apsimx_examples() + + file.copy(file.path(ex.dir, "Wheat.apsimx"), ".") + + lon <- seq(1, 2, length.out = 30) + lat <- seq(48, 49, length.out = 30) + + for(i in seq_along(lon)){ + + sp <- try(get_isric_soil_profile(lonlat = c(lon[i], lat[i]), fix = TRUE, verbose = FALSE), silent = TRUE) + if(inherits(sp, "try-error")){ + cat("No soil for this location. Lon:", lon[i], "Lat:", lat[i], "\n") + next + } + + edit_apsimx_replace_soil_profile("Wheat.apsimx", soil.profile = sp, + edit.tag = paste0("-", i)) + sim1 <- try(apsimx(paste0("Wheat-", i, ".apsimx")), silent = TRUE) + + if(inherits(sim1, "try-error")) + cat("Simulation:", i, "failed\n") + } + } > > > > proc.time() user system elapsed 0.75 0.25 9.29