R Under development (unstable) (2024-08-17 r87027 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. > > ## Testing initialwater with a variety of files > 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.0' > apsimx_options(warn.versions = FALSE) > > run.apsimx.initialwater <- get(".run.local.tests", envir = apsimx.options) > > #### Testing InitialWater ---- > if(run.apsimx.initialwater){ + + tmp.dir <- tempdir() + ex.dir <- auto_detect_apsimx_examples() + ex.dir.list <- dir(ex.dir, pattern = "apsimx$") + + #### I will skip files that require 'root' + ##ex.dir.list2 <- ex.dir.list[c(2, 4, 16:19, 23, 24, 29, 30, 34)] + ex.dir.list3 <- c("Barley.apsimx", "Canola.apsimx", "Maize.apsimx", "Mungbean.apsimx", + "Oats.apsimx", "OilPalm.apsimx", "Potato.apsimx", "RedClover.apsimx", + "Sorghum.apsimx", "Soybean.apsimx", "Wheat.apsimx") + for(.i in ex.dir.list3){ + if(.i == "Slurp.apsimx") stop("This is bananas", call. = FALSE) + cat("Simulation:", .i, "\n") + #### 1) Inspect ---- + cat("Inspecting...\n") + inspect_apsimx(.i, ex.dir, node = "Soil", soil.child = "InitialWater") + pp <- inspect_apsimx(.i, ex.dir, node = "Soil", soil.child = "InitialWater", print.path = TRUE) + #### 2) Extract ---- + cat("Extracting...\n") + edf.iw <- extract_data_apsimx(.i, ex.dir, node = "Soil", soil.child = "InitialWater") + #### 3) Edit ---- + cat("Editing...\n") + if(!file.exists(file.path(tmp.dir, .i))) file.copy(from = file.path(ex.dir, .i), to = tmp.dir) + if(!is.null(edf.iw$second) && nrow(edf.iw$second) > 0){ + initialvalues <- rep(0.3, nrow(edf.iw$second)) + edit_apsimx(.i, tmp.dir, node = "Soil", + soil.child = "InitialWater", + parm = "InitialValues", + value = initialvalues) + #### 4) Check ---- + cat("Checking...\n") + edited.file <- paste0(tools::file_path_sans_ext(.i), "-edited.apsimx") + inspect_apsimx(edited.file, tmp.dir, node = "Soil", soil.child = "InitialWater") + check_apsimx(edited.file, tmp.dir) + } + if(file.exists(file.path(tmp.dir, edited.file))) file.remove(file.path(tmp.dir, edited.file)) + } + } > > > proc.time() user system elapsed 0.48 0.14 0.62