Running 'test_AK_point_sim.R' [159s]
  Running 'test_apsim_met.R' [162s]
  Running 'test_apsim_met_tt.R' [1s]
  Running 'test_apsim_soils.R' [159s]
  Running 'test_apsim_swim.R' [160s]
  Running 'test_apsimx_factorial.R' [1s]
  Running 'test_classic_examples.r' [1s]
  Running 'test_compare_apsim.R' [1s]
  Running 'test_cores_sens_apsimx.R' [168s]
  Running 'test_edit.R' [1s]
  Running 'test_edit_apsim_replace_soil_profile.R' [2s]
  Running 'test_edit_apsim_xml.R' [173s]
  Running 'test_edit_apsimx_json.R' [1s]
  Running 'test_edit_apsimx_replacement.R' [1s]
  Running 'test_edit_batch.R' [164s]
  Running 'test_examples.R' [1s]
  Running 'test_extract_values_apsimx.R' [170s]
  Running 'test_get_daymet_apsim_met.R' [169s]
  Running 'test_get_gsod_apsim_met.R' [155s]
  Running 'test_get_isric_soil_profile.R' [158s]
  Running 'test_grep_json_list.R' [1s]
  Running 'test_insert_replacement_node.R' [173s]
  Running 'test_inspect.R' [173s]
  Running 'test_inspect_apsim_factorial.R' [167s]
  Running 'test_inspect_apsim_xml.R' [161s]
  Running 'test_inspect_apsimx_json.R' [168s]
  Running 'test_optim_apsimx.R' [2s]
  Running 'test_read_apsim.R' [1s]
  Running 'test_read_apsim_met.R' [1s]
  Running 'test_replacements.R' [1s]
  Running 'test_sens_apsimx.R' [2s]
  Running 'test_soil_properties.R' [1s]
  Running 'test_ssurgo2sp.R' [2s]
  Running 'test_vignette.R' [168s]
Running the tests in 'tests/test_AK_point_sim.R' failed.
Complete output:
  > ## Example simulation for a point using APSIM
  > ## Author: Fernando E. Miguez
  > ## Date: 2021-06-08
  > ##
  > ## Required: R package apsimx 1.992
  > 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.point.sim <- get(".run.local.tests", envir = apsimx.options)
  > 
  > tmpd <- tempdir()
  > ## tmpd <- "../tests"
  > ## setwd(tmpd)
  > 
  > if(run.apsimx.point.sim && FALSE){
  + 
  +   site.name <- "ARK1"
  +   site.coords <- c(-90.75973, 34.72834)
  +   
  +   ## Copy Maize from Examples 
  +   exdir <- auto_detect_apsimx_examples()
  +   file.copy(file.path(exdir, "Maize.apsimx"), tmpd)
  +   
  +   ## Get weather from NASAPOWER
  +   ## Important: this is just an example. I recommend looking into
  +   ## whether this is a good source of weather data for this location.
  +   ## This takes a few seconds
  +   pmet <- get_power_apsim_met(site.coords, 
  +                               dates = c("2000-01-01", "2020-12-31"))
  +   check_apsim_met(pmet) ## Some missing values for solar radiation
  +   pmet <- impute_apsim_met(pmet) ## Automatically impute 
  +   check_apsim_met(pmet) ## Now it is okay
  +   write_apsim_met(pmet, wrt.dir = ".", filename = paste0(site.name, ".met")) ## Write to file
  +   
  +   ## Edit the filename for weather
  +   edit_apsimx("Maize.apsimx", node = "Weather",
  +               value = paste0(site.name, ".met"),
  +               overwrite = TRUE)
  +   
  +   inspect_apsimx("Maize.apsimx", node = "Weather")
  +   
  +   ## Also change the clock
  +   edit_apsimx("Maize.apsimx", node = "Clock",
  +               parm = c("Start", "End"),
  +               value = c("2000-01-01T00:00:00", "2020-12-31T00:00:00"),
  +               overwrite = TRUE)
  +   
  +   inspect_apsimx("Maize.apsimx")
  +   
  +   ## Change planting and harvest date
  +   edit_apsimx("Maize.apsimx", node = "Crop", 
  +               parm = "StartDate", value = "1-may", 
  +               overwrite = TRUE)
  +   
  +   edit_apsimx("Maize.apsimx", node = "Crop", 
  +               parm = "EndDate", value = "1-oct", 
  +               overwrite = TRUE)
  + 
  +   inspect_apsimx("Maize.apsimx", node = "Crop")
  +   
  +   sim0 <- apsimx("Maize.apsimx")
  +   
  +   ## Results with default soil
  +   ggplot(sim0, aes(x = Date, y = Maize.AboveGround.Wt)) + geom_point()
  +   
  +   ## Now let's get the soil data from SSURGO
  +   sp0 <- get_ssurgo_soil_profile(site.coords)
  +   
  +   ## Very important: these are just 'template' soil profiles from 
  +   ## where to start. These need to be checked and if you have any site 
  +   ## specific information you should use it
  +   plot(sp0[[1]]) ## Visualize properties
  +   plot(sp0[[1]], property = "water")
  +   ## You might want to use the APSIM-X GUI in addition
  +   
  +   ## Also, here you can modify the metadata, since it is a list
  +   sp0[[1]]$metadata$NearestTown <- "Marianna"
  +   ## You might want to populate the soilwat or swim options
  +   ## using the helper functions soilwat_parms or swim_parms
  +   
  +   edit_apsimx_replace_soil_profile("Maize.apsimx",
  +                                    soil.profile = sp0[[1]],
  +                                    overwrite = TRUE)  
  + 
  +   sim1 <- apsimx("Maize.apsimx")  
  +   
  +   ## Results with ssurgo soil
  +   ggplot(sim1, aes(x = Date, y = Maize.AboveGround.Wt)) + geom_point()
  +   
  +   cmp <- compare_apsim(sim0, sim1, variable = "Maize.AboveGround.Wt")
  +   plot(cmp, variable = "Maize.AboveGround.Wt") ## similar but not identical
  +   
  +   ## There is no site information
  +   inspect_apsimx("Maize.apsimx", node = "Soil", parm = "Site")
  +   ## However, the nearest town was edited as expected
  +   inspect_apsimx("Maize.apsimx", node = "Soil", parm = "NearestTown")
  +   
  +   ## If we still want to edit the Site
  +   edit_apsimx("Maize.apsimx", node = "Soil", 
  +               parm = "Site", value = "AK1", 
  +               overwrite = TRUE)
  +   
  +   inspect_apsimx("Maize.apsimx", node = "Soil")
  + }
  > 
  > proc.time()
     user  system elapsed 
     1.21    0.17    1.37 
Running the tests in 'tests/test_apsim_met.R' failed.
Complete output:
  > ## Testing apsim_met suite of functions
  > ## Some observations:
  > ##
  > ## 1. check should never fail. It should always return warnings
  > ## 2. napad should work for many different tricky situations
  > 
  > 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)
  > 
  > run.apsim.met <- get(".run.local.tests", envir = apsimx.options)
  > 
  > if(.Platform$OS.type == "unix"){
  +   internet <- !is.null(utils::nsl("google.com"))
  + }else{
  +   internet <- FALSE  
  + }
  >   
  > if(run.apsim.met && internet){
  +   
  +   ## Testing napad and impute
  +   ## Buenos Aires 34d 36 12, 58 22 54 W
  +   bsas.lat <- unit_conv("34d 36' 12\" W", from = "degrees", to = "decimal")
  +   bsas.lon <- unit_conv("58d 22' 54\" S", from = "degrees", to = "decimal")
  +   
  +   pwr <- get_power_apsim_met(lonlat = c(bsas.lon, bsas.lat), dates = c("2010-01-01", "2015-12-31"))
  +   check_apsim_met(pwr)
  +   gsd <- get_gsod_apsim_met(lonlat = c(bsas.lon, bsas.lat), dates = c("2010-01-01", "2015-12-31"))
  +   check_apsim_met(gsd)
  +   gsd$radn <- pwr$radn
  +   check_apsim_met(gsd)
  +   gsd.impt <- impute_apsim_met(gsd)
  +   check_apsim_met(gsd.impt)
  +   
  +   ## Test for Brazil (Sao Paulo)
  +   ## 23 33′S 46 38′W
  +   sp.lat <- unit_conv("23d 33' 0\" W", from = "degrees", to = "decimal")
  +   sp.lon <- unit_conv("46d 38' 0\" S", from = "degrees", to = "decimal")
  +   
  +   pwr <- get_power_apsim_met(lonlat = c(sp.lon, sp.lat), dates = c("2010-01-01", "2015-12-31"))
  +   check_apsim_met(pwr)
  +   
  +   plot(pwr, met.var = "rain", years = 2010:2015, cumulative = TRUE, climatology = TRUE)
  +   
  +   gsd <- get_gsod_apsim_met(lonlat = c(sp.lon, sp.lat), dates = c("2010-01-01", "2015-12-31"), fillin.radn = TRUE)
  +   check_apsim_met(gsd)
  +   gsd.np <- napad_apsim_met(gsd)
  +   gsd.imp <- impute_apsim_met(gsd.np)
  +   check_apsim_met(gsd.imp) ## Rain variable is missing
  +   plot(gsd.imp, met.var = "radn", years = 2010:2015, cumulative = TRUE, climatology = TRUE)
  +   
  +   ## Test for Daymet data
  +   dmt <- get_daymet2_apsim_met(lonlat = c(-93, 42), years = c(2000, 2020))
  +   check_apsim_met(dmt)
  +   dmt.np <- napad_apsim_met(dmt)  
  +   dmt.imp <- impute_apsim_met(dmt.np)
  +   check_apsim_met(dmt.imp)
  +   
  +   summary(dmt.imp)
  +   plot(dmt.imp)
  +   plot(dmt.imp, met.var = "rain", years = 2010:2015, cumulative = TRUE, climatology = TRUE)
  + }
  > 
  > ## Testing the feature for adding a column to a met file
  > if(run.apsim.met && internet){
  +   
  +   ## Testing adding a column
  +   extd.dir <- system.file("extdata", package = "apsimx")
  +   ames <- read_apsim_met("Ames.met", src.dir = extd.dir)
  +   
  +   ## ames$vp <- 5 This does not work and it is not supposed to 
  +   
  +   vp <- data.frame(vp = abs(rnorm(nrow(ames), 2)))
  +   attr(vp, "units") <- "(hPa)"
  +   
  +   ames$vp <- vp
  + 
  +   val <- abs(rnorm(nrow(ames), 2))
  +   nm <- "vp"
  +   ames <- add_column_apsim_met(ames, value = val, name = "vp", units = "(hPa)")
  +   
  +   ## Extra tests
  +   ames <- ames[ames$year < 2018, ]
  +   ames <- apsimx:::pp_apsim_met(ames)
  +   ames <- tt_apsim_met(ames, dates = c("01-05", "30-10"), method = "Classic_TT")
  +   
  +   plot(ames, met.var = "photoperiod")
  +   plot(ames, met.var = "Classic_TT")
  +     
  + }
  > 
  > if(run.apsim.met){
  +  
  +   iem <- get_iem_apsim_met(lonlat = c(-93.77, 42.02), 
  +                            dates = c("2013-01-01","2013-12-31"))
  +   
  +   pwr <- get_power_apsim_met(lonlat = c(-93.77, 42.02), 
  +                            dates = c("2013-01-01","2013-12-31"))
  +   
  +   dmt <- get_daymet_apsim_met(lonlat = c(-93.77, 42.02), 
  +                               years = 2013)
  +   
  +   cmp <- compare_apsim_met(iem, pwr[, 1:6], dmt[, 1:6], 
  +                            labels = c("IEM", "POWER", "DAYMET"))
  +   
  +   cmp <- compare_apsim_met(iem, pwr[, 1:6], dmt[, 1:6], 
  +                            met.var = "rain",
  +                            labels = c("IEM", "POWER", "DAYMET"))
  + 
  +   plot(cmp)
  +   plot(cmp, plot.type = "ts")
  +   plot(cmp, plot.type = "ts", met.var = "rain", cumulative = TRUE)
  + 
  + }
  > 
  > if(run.apsim.met){
  +   
  +   ## Testing the graph functionality
  +   pwr <- get_power_apsim_met(lonlat = c(-93.77, 42.02), 
  +                              dates = c("1990-01-01","2020-12-31"))
  +   
  +   ## Plotting using the density option
  +   plot(pwr, plot.type = "density")
  +   plot(pwr, plot.type = "density", met.var = "radn")
  +   plot(pwr, plot.type = "density", met.var = "rain")
  +   
  +   ## Plotting using the density option
  +   plot(pwr, plot.type = "density", climatology = TRUE)
  +   plot(pwr, plot.type = "density", met.var = "radn", climatology = TRUE)
  +   plot(pwr, plot.type = "density", met.var = "rain", climatology = TRUE)
  +   
  +   plot(pwr, plot.type = "density", climatology = TRUE, years = c(2012, 2019))
  +   plot(pwr, plot.type = "density", met.var = "radn", climatology = TRUE, years = c(2012, 2019))
  +   plot(pwr, plot.type = "density", met.var = "rain", climatology = TRUE, years = c(2012, 2019))
  + 
  +   plot(pwr, plot.type = "density", summary = TRUE)
  +   plot(pwr, plot.type = "density", met.var = "radn_sum", summary = TRUE)
  +   plot(pwr, plot.type = "density", met.var = "rain", summary = TRUE)
  +   
  +   ## Testing the options with individual years
  +   plot(pwr, plot.type = "density", summary = TRUE, years = c(2012:2015))
  +   plot(pwr, plot.type = "density", met.var = "radn", summary = TRUE, years = c(2012, 2019))
  +   plot(pwr, plot.type = "density", met.var = "rain", summary = TRUE, years = c(2015, 2017))
  +   
  +   ## Testing with climatology and years
  +   plot(pwr, plot.type = "density", met.var = "rain", summary = TRUE, climatology = TRUE, years = c(2012, 2019))
  +   plot(pwr, plot.type = "density", met.var = "radn_sum", summary = TRUE, climatology = TRUE, years = c(2012, 2019))
  +   plot(pwr, plot.type = "density", met.var = "avg_maxt", summary = TRUE, climatology = TRUE, years = c(2012, 2019))
  + 
  + }
  > 
  > proc.time()
     user  system elapsed 
     0.79    0.18    0.95 
Running the tests in 'tests/test_apsim_soils.R' failed.
Complete output:
  > ## 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
  > 
  > 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 
     1.10    0.32    5.57 
Running the tests in 'tests/test_apsim_swim.R' failed.
Complete output:
  > ## Test APSIM SWIM code for 'Classic'
  > 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)
  > 
  > ## This test does not need APSIM Classic to run
  > run.test.apsim.swim <- TRUE
  > 
  > ## Only write to a temp directory
  > tmp.dir <- tempdir()
  > 
  > extd.dir <- system.file("extdata", package = "apsimx")
  > 
  > if(run.test.apsim.swim){
  + 
  +   inspect_apsim("maize-swim.apsim", src.dir = extd.dir)  
  +   inspect_apsim("maize-swim.apsim", src.dir = extd.dir, node = "Weather")  
  +   inspect_apsim("maize-swim.apsim", src.dir = extd.dir, 
  +                 node = "Soil", soil.child = "Water") 
  +   inspect_apsim("maize-swim.apsim", src.dir = extd.dir, 
  +                 node = "Soil", soil.child = "SWIM") 
  +   edit_apsim("maize-swim.apsim", 
  +              src.dir = extd.dir, wrt.dir = tmp.dir,
  +              node = "Soil", soil.child = "SWIM",
  +              parm = "Salb", value = 0.10) 
  +   inspect_apsim("maize-swim-edited.apsim", src.dir = tmp.dir, 
  +                 node = "Soil", soil.child = "SWIM") 
  +   edit_apsim("maize-swim-edited.apsim", 
  +              src.dir = tmp.dir, wrt.dir = tmp.dir,
  +              overwrite = TRUE,
  +              node = "Soil", soil.child = "SWIM",
  +              parm = "WaterTableDepth", value = 1500)
  +   inspect_apsim("maize-swim-edited.apsim", src.dir = tmp.dir, 
  +                 node = "Soil", soil.child = "SWIM") 
  +   
  + }
  start_date : 01/01/2010 
  end_date : 09/11/2019 
  Met file: boone-10-19.met 
  Soil Type:  Canisteo 
  Latitude:  44.7892 
  Longitude:  -95.2114 
  
  
  |Depth   | maize LL| maize KL| maize XF| soybean LL| soybean KL| soybean XF| wheat LL| wheat KL| wheat XF| maize LL| maize KL| maize XF| soybean LL| soybean KL| soybean XF| wheat LL| wheat KL| wheat XF| Thickness|    BD| AirDry|  LL15|   DUL|   SAT|      KS|
  |:-------|--------:|--------:|--------:|----------:|----------:|----------:|--------:|--------:|--------:|--------:|--------:|--------:|----------:|----------:|----------:|--------:|--------:|--------:|---------:|-----:|------:|-----:|-----:|-----:|-------:|
  |0-25    |    0.234|    0.080|        1|      0.234|      0.080|          1|    0.234|     0.08|        1|    0.234|    0.080|        1|      0.234|      0.080|          1|    0.234|     0.08|        1|       250| 1.400|  0.211| 0.234| 0.345| 0.422| 792.567|
  |25-50   |    0.234|    0.069|        1|      0.234|      0.069|          1|    0.234|     0.07|        1|    0.234|    0.069|        1|      0.234|      0.069|          1|    0.234|     0.07|        1|       250| 1.400|  0.234| 0.234| 0.345| 0.422| 792.567|
  |50-54   |    0.212|    0.062|        1|      0.212|      0.062|          1|    0.212|     0.06|        1|    0.212|    0.062|        1|      0.212|      0.062|          1|    0.212|     0.06|        1|        40| 1.425|  0.212| 0.212| 0.330| 0.412| 792.567|
  |54-58   |    0.212|    0.061|        1|      0.212|      0.061|          1|    0.212|     0.06|        1|    0.212|    0.061|        1|      0.212|      0.061|          1|    0.212|     0.06|        1|        40| 1.425|  0.212| 0.212| 0.330| 0.412| 792.567|
  |58-77   |    0.137|    0.056|        1|      0.137|      0.056|          1|    0.137|     0.06|        1|    0.137|    0.056|        1|      0.137|      0.056|          1|    0.137|     0.06|        1|       190| 1.400|  0.137| 0.137| 0.272| 0.422| 792.567|
  |77-96   |    0.137|    0.049|        1|      0.137|      0.049|          1|    0.137|     0.05|        1|    0.137|    0.049|        1|      0.137|      0.049|          1|    0.137|     0.05|        1|       190| 1.400|  0.137| 0.137| 0.272| 0.422| 792.567|
  |96-124  |    0.154|    0.040|        1|      0.154|      0.040|          1|    0.154|     0.04|        1|    0.154|    0.040|        1|      0.154|      0.040|          1|    0.154|     0.04|        1|       280| 1.525|  0.154| 0.154| 0.290| 0.310| 792.567|
  |124-152 |    0.154|    0.030|        1|      0.154|      0.030|          1|    0.154|     0.03|        1|    0.154|    0.030|        1|      0.154|      0.030|          1|    0.154|     0.03|        1|       280| 1.525|  0.154| 0.154| 0.290| 0.320|   1.000|
  |152-158 |    0.154|    0.000|        0|      0.154|      0.030|          1|    0.154|     0.03|        1|    0.154|    0.000|        0|      0.154|      0.030|          1|    0.154|     0.03|        1|        60| 1.525|  0.154| 0.154| 0.290| 0.310|   0.001|
  Soil Type:  Canisteo 
  Latitude:  44.7892 
  Longitude:  -95.2114 
  
  
  |parm                       |value |
  |:--------------------------|:-----|
  |Salb                       |0.13  |
  |CN2Bare                    |75    |
  |CNRed                      |20    |
  |CNCov                      |0.8   |
  |KDul                       |0.1   |
  |PSIDul                     |-100  |
  |VC                         |true  |
  |DTmin                      |0     |
  |DTmax                      |1440  |
  |MaxWaterIncrement          |10    |
  |SpaceWeightingFactor       |0     |
  |SoluteSpaceWeightingFactor |0     |
  |Diagnostics                |false |
  
  
  |parm                               |value |
  |:----------------------------------|:-----|
  |SwimWaterTable : WaterTableDepth   |2000  |
  |SwimSubsurfaceDrain : DrainDepth   |1200  |
  |SwimSubsurfaceDrain : DrainSpacing |6100  |
  |SwimSubsurfaceDrain : DrainRadius  |38    |
  |SwimSubsurfaceDrain : Klat         |1000  |
  |SwimSubsurfaceDrain : ImpermDepth  |3000  |
  Edited .//Soil/Swim/Salb 
  Edited parameter Salb 
  New values  0.1 
  Created  D:\temp\RtmpGWKzTw/maize-swim-edited.apsim 
  Soil Type:  Canisteo 
  Latitude:  44.7892 
  Longitude:  -95.2114 
  
  
  |parm                       |value |
  |:--------------------------|:-----|
  |Salb                       |0.1   |
  |CN2Bare                    |75    |
  |CNRed                      |20    |
  |CNCov                      |0.8   |
  |KDul                       |0.1   |
  |PSIDul                     |-100  |
  |VC                         |true  |
  |DTmin                      |0     |
  |DTmax                      |1440  |
  |MaxWaterIncrement          |10    |
  |SpaceWeightingFactor       |0     |
  |SoluteSpaceWeightingFactor |0     |
  |Diagnostics                |false |
  
  
  |parm                               |value |
  |:----------------------------------|:-----|
  |SwimWaterTable : WaterTableDepth   |2000  |
  |SwimSubsurfaceDrain : DrainDepth   |1200  |
  |SwimSubsurfaceDrain : DrainSpacing |6100  |
  |SwimSubsurfaceDrain : DrainRadius  |38    |
  |SwimSubsurfaceDrain : Klat         |1000  |
  |SwimSubsurfaceDrain : ImpermDepth  |3000  |
  Edited .//Soil/Swim/SwimWaterTable/WaterTableDepth 
  Edited parameter WaterTableDepth 
  New values  1500 
  Created  D:\temp\RtmpGWKzTw/maize-swim-edited.apsim 
  Soil Type:  Canisteo 
  Latitude:  44.7892 
  Longitude:  -95.2114 
  
  
  |parm                       |value |
  |:--------------------------|:-----|
  |Salb                       |0.1   |
  |CN2Bare                    |75    |
  |CNRed                      |20    |
  |CNCov                      |0.8   |
  |KDul                       |0.1   |
  |PSIDul                     |-100  |
  |VC                         |true  |
  |DTmin                      |0     |
  |DTmax                      |1440  |
  |MaxWaterIncrement          |10    |
  |SpaceWeightingFactor       |0     |
  |SoluteSpaceWeightingFactor |0     |
  |Diagnostics                |false |
  
  
  |parm                               |value |
  |:----------------------------------|:-----|
  |SwimWaterTable : WaterTableDepth   |1500  |
  |SwimSubsurfaceDrain : DrainDepth   |1200  |
  |SwimSubsurfaceDrain : DrainSpacing |6100  |
  |SwimSubsurfaceDrain : DrainRadius  |38    |
  |SwimSubsurfaceDrain : Klat         |1000  |
  |SwimSubsurfaceDrain : ImpermDepth  |3000  |
  > 
  > proc.time()
     user  system elapsed 
     0.79    0.21    1.00 
Running the tests in 'tests/test_cores_sens_apsimx.R' failed.
Complete output:
  > ## Script to test cores functionality
  > 
  > 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)
  > 
  > apsimx_options(warn.versions = FALSE)
  > 
  > run.test.two.cores.sns <- FALSE
  > 
  > if(run.test.two.cores.sns){
  + 
  +     tmp.dir <- tempdir()
  +     setwd(tmp.dir)
  +     ex.dir <- auto_detect_apsimx_examples()
  + 
  +     file.copy(file.path(ex.dir, "Wheat.apsimx"), ".")
  +   
  +     pp1 <- inspect_apsimx("Wheat.apsimx", src.dir = ".", 
  +                            node = "Manager", parm = list("SowingFertiliser", 1))
  +     pp1 <- paste0(pp1, ".Amount")
  +   
  +     pp2 <- inspect_apsimx("Wheat.apsimx", src.dir = ".", 
  +                            node = "Manager", parm = list("SowingRule1", 9))
  +     pp2 <- paste0(pp2, ".Population")
  +   
  +     ## The names in the grid should (partially) match the parameter path names
  +     grd <- expand.grid(Fertiliser = c(50, 100, 150), Population = c(100, 200, 300))
  +   
  +     ## This takes 2-3 minutes
  +     system.time(sns0 <- sens_apsimx(file = "Wheat.apsimx", 
  +                                     src.dir = ".",
  +                                     parm.paths = c(pp1, pp2),
  +                                     grid = grd))
  +     ## date        user  system  elapsed 
  +     ## 2022-11-22   215        8     125 (2.08 minutes)
  +   
  +     ## The two core simulation seems to work when number of simulations are even for n - 1
  +     system.time(sns1 <- sens_apsimx(file = "Wheat.apsimx", 
  +                                     src.dir = ".",
  +                                     parm.paths = c(pp1, pp2),
  +                                     grid = grd,
  +                                     cores = 2))
  + 
  +     ## Make sure that data.frames are the same
  +     
  +     ## date        user system elapsed
  +     ## 2022-11-22   292     11    100 (1.67 minutes. It takes 84% of the time compared to 1 core)
  +     
  +     ## Are the results identical?
  +     is.it.zero <- sum(colSums(sns0$grid.sims - sns1$grid.sims))
  +     if(is.it.zero > 0.5)
  +       stop("Results are not identical when cores = 1 and cores = 2")
  +     
  +     ## Testing having uneven number of simulations to parallelize
  +     grd2 <- grd[1:8, ]
  +     
  +     system.time(sns2 <- sens_apsimx(file = "Wheat.apsimx", 
  +                                     src.dir = ".",
  +                                     parm.paths = c(pp1, pp2),
  +                                     grid = grd2,
  +                                     cores = 2))
  +     
  +     nrow.sns2 <- nrow(sns2$grid.sims)
  +     ## Compare results
  +     is.it.zero <- sum(colSums(sns1$grid.sims[1:8,] - sns2$grid.sims))
  +     
  +     if(is.it.zero > 0.5)
  +       stop("Results are not identical when cores = 1 and cores = 2")
  +   
  + }
  > 
  > run.test.more.cores.sns <- FALSE
  > 
  > 
  > if(run.test.more.cores.sns){
  +   
  +   tmp.dir <- tempdir()
  +   setwd(tmp.dir)
  +   ex.dir <- auto_detect_apsimx_examples()
  +   
  +   file.copy(file.path(ex.dir, "Wheat.apsimx"), ".")
  +   
  +   pp1 <- inspect_apsimx("Wheat.apsimx", src.dir = ".", 
  +                         node = "Manager", parm = list("SowingFertiliser", 1))
  +   pp1 <- paste0(pp1, ".Amount")
  +   
  +   pp2 <- inspect_apsimx("Wheat.apsimx", src.dir = ".", 
  +                         node = "Manager", parm = list("SowingRule1", 9))
  +   pp2 <- paste0(pp2, ".Population")
  +   
  +   ## The names in the grid should (partially) match the parameter path names
  +   grd <- expand.grid(Fertiliser = c(50, 100, 150), Population = c(100, 200, 300))
  +   
  +   system.time(sns3 <- sens_apsimx(file = "Wheat.apsimx", 
  +                                  src.dir = ".",
  +                                  parm.paths = c(pp1, pp2),
  +                                  grid = grd,
  +                                  cores = 3))
  +   
  +   ## Compare results
  +   is.it.zero <- sum(colSums(sns1$grid.sims - sns3$grid.sims))
  +   
  +   if(is.it.zero > 0.5)
  +     stop("Results are not identical when cores = 2 and cores = 3")
  +   
  +   grd2 <- grd[1:8, ]
  + 
  +   system.time(sns4 <- sens_apsimx(file = "Wheat.apsimx", 
  +                                   src.dir = ".",
  +                                   parm.paths = c(pp1, pp2),
  +                                   grid = grd2,
  +                                   cores = 3))
  +   
  +   ## Compare results
  +   is.it.zero <- sum(colSums(sns2$grid.sims - sns4$grid.sims))
  +   
  +   if(is.it.zero > 0.5)
  +     stop("Results are not identical when cores = 2 and cores = 3 (smaller grid)")
  +   
  +   ## Trying more cores
  +   system.time(sns5 <- sens_apsimx(file = "Wheat.apsimx", 
  +                                   src.dir = ".",
  +                                   parm.paths = c(pp1, pp2),
  +                                   grid = grd,
  +                                   cores = 4))
  +   
  +   is.it.zero <- sum(colSums(sns1$grid.sims - sns5$grid.sims))
  +   
  +   if(is.it.zero > 0.5)
  +     stop("Results are not identical when cores = 3 and cores = 4")
  +   
  +   
  + }
  > 
  > ## Testing the 'save' feature
  > 
  > run.test.save.cores.sns <- FALSE
  > 
  > if(run.test.save.cores.sns){
  +   
  +   tmp.dir <- tempdir()
  +   setwd(tmp.dir)
  +   ex.dir <- auto_detect_apsimx_examples()
  +   
  +   file.copy(file.path(ex.dir, "Wheat.apsimx"), ".")
  +   
  +   pp1 <- inspect_apsimx("Wheat.apsimx", src.dir = ".", 
  +                         node = "Manager", parm = list("SowingFertiliser", 1))
  +   pp1 <- paste0(pp1, ".Amount")
  +   
  +   pp2 <- inspect_apsimx("Wheat.apsimx", src.dir = ".", 
  +                         node = "Manager", parm = list("SowingRule1", 9))
  +   pp2 <- paste0(pp2, ".Population")
  +   
  +   ## The names in the grid should (partially) match the parameter path names
  +   grd <- expand.grid(Fertiliser = c(50, 100, 150), Population = c(100, 200, 300))
  +   
  +   ## This takes 2-3 minutes
  +   system.time(sns01 <- sens_apsimx(file = "Wheat.apsimx", 
  +                                   src.dir = ".",
  +                                   parm.paths = c(pp1, pp2),
  +                                   grid = grd,
  +                                   save = TRUE))
  +   
  +   ## This takes 2-3 minutes
  +   system.time(sns02 <- sens_apsimx(file = "Wheat.apsimx", 
  +                                   src.dir = ".",
  +                                   parm.paths = c(pp1, pp2),
  +                                   grid = grd,
  +                                   save = "wheat_int_results.csv"))
  +   
  + }
  > 
  > proc.time()
     user  system elapsed 
     0.76    0.10    0.89 
Running the tests in 'tests/test_edit_apsim_xml.R' failed.
Complete output:
  > ## Testing the 'edit_apsim_xml' 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)
  > 
  > ## I guess I can run this non-locally
  > extd.dir <- system.file("extdata", package = "apsimx")
  > 
  > tmp.dir <- tempdir()
  >  
  > values <- paste(rep(1.7, 12), collapse = " ")
  >  
  > edit_apsim_xml("Maize75.xml", 
  +                 src.dir = extd.dir,
  +                 wrt.dir = tmp.dir, 
  +                 parm.path = ".//Model/rue",
  +                 value = values)
  Edited .//Model/rue 
  Paramter path: /Type/Model/rue 
  New values  1.7 1.7 1.7 1.7 1.7 1.7 1.7 1.7 1.7 1.7 1.7 1.7 
  Created  D:\temp\Rtmp04i2lS/Maize75-edited.xml 
  > 
  > pp1 <- edit_apsim_xml("Maize75.xml", 
  +                       src.dir = extd.dir,
  +                       wrt.dir = tmp.dir, 
  +                       parm.path = ".//Model/rue",
  +                       value = values,
  +                       verbose = FALSE)
  > 
  > pp2 <- edit_apsim_xml("Maize75.xml", 
  +                       src.dir = extd.dir,
  +                       wrt.dir = tmp.dir, 
  +                       parm.path = ".//rue",
  +                       value = values,
  +                       verbose = FALSE)
  > 
  > proc.time()
     user  system elapsed 
     0.76    0.18    0.93 
Running the tests in 'tests/test_edit_batch.R' failed.
Complete output:
  > ## This is my way of doing this now
  > 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)
  > apsimx_options(warn.versions = FALSE)
  > 
  > extd.dir <- system.file("extdata", package = "apsimx")
  > 
  > run.test.edit.apsimx.batch <- get(".run.local.tests", envir = apsimx.options)
  > 
  > tmp.dir <- tempdir()
  > 
  > if(run.test.edit.apsimx.batch){
  + 
  +   file.copy(paste0(extd.dir, "/", "Wheat.apsimx"), tmp.dir)
  + 
  +   inspect_apsimx("Wheat.apsimx", src.dir = tmp.dir, node = "SurfaceOrganicMatter")
  + 
  +   edit1time <- system.time(edit_apsimx("Wheat.apsimx", src.dir = tmp.dir,
  +                                        wrt.dir = tmp.dir,
  +                                        node = "SurfaceOrganicMatter", 
  +                                        parm = "InitialResidueMass", value = 600))
  + 
  +   inspect_apsimx("Wheat-edited.apsimx", src.dir = tmp.dir, node = "SurfaceOrganicMatter")
  + 
  +   ## Using the 'batch' method
  +   ## Let's say I want to edit 'SurfaceOrganicMatter'
  +   ## InitialResidueMass from 500 to 650
  +   ## Understanding the structure of JSON files
  +   parms <- list(".Simulations.Simulation.Field.SurfaceOrganicMatter.InitialResidueMass" = 650)
  +   edit2time <- system.time(edit_apsimx_batch("Wheat.apsimx", src.dir = tmp.dir, parms = parms))
  +   inspect_apsimx("Wheat.apsimx", src.dir = tmp.dir, node = "SurfaceOrganicMatter")
  +   
  +   ## What is the difference in 'elapsed' real time?
  +   edit2time[[3]]/edit1time[[3]]
  + } 
  > 
  > proc.time()
     user  system elapsed 
     0.64    0.21    0.85 
Running the tests in 'tests/test_extract_values_apsimx.R' failed.
Complete output:
  > ## Testing the function for extracting values from an arbitrary .apsimx file
  > ## using extract_value_apsimx
  > 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)
  > 
  > run.extract.value.apsimx <- FALSE
  > 
  > if(run.extract.value.apsimx){
  +   
  +   ## Testing with the Barley.apsimx example
  +   ex.dir <- auto_detect_apsimx_examples()
  +   
  +   pp1 <- inspect_apsimx("Barley.apsimx", src.dir = ex.dir)
  +   ## Extract value of Start
  +   extract_values_apsimx("Barley.apsimx", src.dir = ex.dir,
  +                         parm.path = paste0(pp1, ".Start"))
  +   ## Extract value of End
  +   extract_values_apsimx("Barley.apsimx", src.dir = ex.dir,
  +                         parm.path = paste0(pp1, ".End"))
  +   ## Weather
  +   pp2 <- inspect_apsimx("Barley.apsimx", src.dir = ex.dir, 
  +                         node = "Weather")
  +   ## Extract weather file
  +   extract_values_apsimx("Barley.apsimx", src.dir = ex.dir,
  +                         parm.path = paste0(pp2, ".FileName"))
  +   ## Manager
  +   pp3 <- inspect_apsimx("Barley.apsimx", src.dir = ex.dir, 
  +                         node = "Manager", parm = list("Sowing", 1))
  +   ## Extract fertilizer amount
  +   extract_values_apsimx("Barley.apsimx", src.dir = ex.dir,
  +                         parm.path = paste0(pp3, ".Amount"))
  +   ## Row Spacing
  +   pp4 <- inspect_apsimx("Barley.apsimx", src.dir = ex.dir, 
  +                         node = "Manager", parm = list("fixed", 5))
  +   ## Extract the row spacing
  +   ex.rs <- extract_values_apsimx("Barley.apsimx", src.dir = ex.dir,
  +                                  parm.path = paste0(pp4, ".RowSpacing"))
  +   
  +   ## What about vectors?
  +   pp5 <- inspect_apsimx("Barley.apsimx", src.dir = ex.dir, node = "Soil",
  +                         soil.child = "Physical", parm = "DUL")
  +   ## Extract DUL
  +   ex.dul <- extract_values_apsimx("Barley.apsimx", src.dir = ex.dir,
  +                                   parm.path = paste0(pp5, ".DUL"))
  +   
  +   ## On the replacement example
  +   extd.dir <- system.file("extdata", package = "apsimx")
  +   pp6 <- inspect_apsimx_replacement("MaizeSoybean.apsimx", src.dir = extd.dir,
  +                                     node = "Soybean",
  +                                     node.child = "Leaf", node.subchild = "ExtinctionCoeff",
  +                                     node.subsubchild = "XYPairs", parm = "Y")
  +   ## Extract it
  +   ext.exc <- extract_values_apsimx("MaizeSoybean.apsimx", src.dir = extd.dir,
  +                                    parm.path = pp6)
  +   ## Try RUE
  +   pp7 <- inspect_apsimx_replacement("MaizeSoybean.apsimx", src.dir = extd.dir,
  +                                     node = "Soybean",
  +                                     node.child = "Leaf", node.subchild = "Photosynthesis", 
  +                                     node.subsubchild = "RUE", parm = "FixedValue")
  +   ext.rue <- extract_values_apsimx("MaizeSoybean.apsimx", src.dir = extd.dir, parm.path = pp7)
  + }
  > 
  > proc.time()
     user  system elapsed 
     0.84    0.17    1.00 
Running the tests in 'tests/test_get_daymet_apsim_met.R' failed.
Complete output:
  > ## Testing the get_daymet_apsim_met function
  > ## Note (2020-02-09)
  > ## I've ran this test several times now on Mac and Windows
  > ## I won't run it again until it is needed
  > ## However, note that the source of weather data can
  > ## have a large impact on final yield estimates
  > ## the difference is 171.1547 g per meter squared
  > ## with higher values for power over daymet
  > ## Note (2020-06-15): This takes for ever, I'm not running it for a while
  > 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)
  > apsimx_options(warn.versions = FALSE)
  > 
  > run.test.daymet0 <- FALSE
  > 
  > run.test.daymet <- get(".run.local.tests", envir = apsimx.options) & run.test.daymet0
  > 
  > username <- Sys.info()[["user"]]
  > 
  > tmp.dir <- tempdir()
  > 
  > if(run.test.daymet && username == "fernandomiguez"){
  + 
  +   lonlat <- c(-93, 42)
  +   
  +   dmet <- get_daymet_apsim_met(lonlat = lonlat, 
  +                                years = 2015:2016,
  +                                width.height = c(1e-5,1e-5),
  +                                raw.dir = paste0(tmp.dir,"/RAW/DAYMET"),
  +                                extraction.dir = paste0(tmp.dir, "/EXTRACTIONS/CIA/DAYMET"),
  +                                label = "CIA",
  +                                filename = "cia-daymet.met",
  +                                cleanup = FALSE)  
  +   
  +   dmet2 <- get_daymet2_apsim_met(lonlat = lonlat, years = 2015:2016)
  +   
  +   cia.daymet <- read_apsim_met("/cia-daymet.met", src.dir = tmp.dir)
  +   
  +   check_apsim_met(cia.daymet)
  + }
  > 
  > ## Does the file produced by DayMet work in APSIM?
  > 
  > run.test.maize.daymet <- get(".run.local.tests", envir = apsimx.options) & run.test.daymet0
  > 
  > if(run.test.maize.daymet && username == "fernandomiguez"){
  + 
  +   extd.dir <- system.file("extdata", package = "apsimx")
  + 
  +   edit_apsimx("Maize.apsimx", 
  +               node = "Clock", 
  +               src.dir = extd.dir, 
  +               wrt.dir = tmp.dir,
  +               parm = c("Start","End"),
  +               value = c("2015-01-01","2016-12-30"),
  +               overwrite = FALSE)
  + 
  +   inspect_apsimx("Maize-edited.apsimx", src.dir = tmp.dir, node = "Clock")
  + 
  +   edit_apsimx("Maize-edited.apsimx", 
  +               src.dir = tmp.dir, wrt.dir = tmp.dir,
  +               node = "Weather", 
  +               value = "cia-daymet.met",
  +               overwrite = TRUE)
  + 
  +   inspect_apsimx("Maize-edited.apsimx", src.dir = tmp.dir, node = "Weather")
  + 
  +   maize.daymet <- apsimx("Maize-edited.apsimx", src.dir = tmp.dir, value = "report")
  + 
  + }
  > 
  > ## What if I get data from POWER?
  > 
  > run.test.power <- get(".run.local.tests", envir = apsimx.options) & run.test.daymet0
  > 
  > if(run.test.power && username == "fernandomiguez"){
  + 
  +   lonlat <- c(-93, 42)
  + 
  +   pwr <- get_power_apsim_met(lonlat = lonlat, wrt.dir = tmp.dir,
  +                              dates = c("2015-01-01","2016-12-31"),
  +                              filename = "cia-power.met")
  +   
  +   pwr.met <- read_apsim_met("cia-power.met", src.dir = tmp.dir)
  +   
  +   check_apsim_met(pwr.met)
  +   
  +   pwr.met$radn <- ifelse(pwr.met$radn == -99, NA, pwr.met$radn)
  +     
  +   pwr.met2 <- impute_apsim_met(pwr.met, verbose = TRUE)
  +   
  +   check_apsim_met(pwr.met2)
  +   
  +   write_apsim_met(pwr.met2, wrt.dir = tmp.dir, filename = "cia-power2.met")
  + }
  > 
  > run.test.maize.power <- get(".run.local.tests", envir = apsimx.options) & run.test.daymet0
  > 
  > if(run.test.maize.daymet && username == "fernandomiguez"){
  +   
  +   edit_apsimx("Maize-edited.apsimx", node = "Weather", 
  +               value = "cia-power2.met", src.dir = tmp.dir,
  +               edit.tag = "-power")
  +   
  +   maize.power <- apsimx("Maize-edited-power.apsimx", 
  +                         src.dir = tmp.dir, value = "report")
  +   
  +   yld.diff <- maize.power$Maize.Grain.Wt - maize.daymet$Maize.Grain.Wt
  + }
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.75    0.14    0.87 
Running the tests in 'tests/test_get_gsod_apsim_met.R' failed.
Complete output:
  > ## Testing GSOD in general and the radiation fill in feature
  > ##
  > 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)
  > 
  > ## This is for UGANDA
  > lonlat <- c(33, 1)
  > dates <- c("2000-01-01", "2019-01-01")
  > 
  > if(FALSE){
  +   ## Without filling in missing radiation data
  +   gsd <- get_gsod_apsim_met(lonlat = lonlat, dates = dates)
  +   ## Test fillin.radn feature
  +   gsd2 <- get_gsod_apsim_met(lonlat = lonlat, dates = dates, fillin.radn = TRUE)
  +   
  +   ## Test padding and imputation
  +   gsd.napad <- napad_apsim_met(gsd)
  +   gsd2.napad <- napad_apsim_met(gsd2)
  +   
  +   ## This shows that impute does not work on the edges
  +   gsd2.impt <- impute_apsim_met(gsd2.napad)
  + }
  > 
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.89    0.10    0.98 
Running the tests in 'tests/test_get_isric_soil_profile.R' failed.
Complete output:
  > ## Testing downloading soil data from ISRIC
  > ## In repeated testing it seems that speed slows down when multiple queries are requested
  > 
  > 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)
  > 
  > run.test.isric.workflow <- get(".run.local.tests", envir = apsimx.options)
  > 
  > if(run.test.isric.workflow){
  +   
  +   # This takes a few seconds
  +   system.time(sp1 <- get_isric_soil_profile(lonlat = c(-93, 42))) ## 1.508 seconds
  +   system.time(sp2 <- get_ssurgo_soil_profile(lonlat = c(-93, 42)))  ## 1.858 seconds
  +   
  +   plot(sp1)
  +   
  +   plot(sp2[[1]])
  +   
  +   ## Only get SSURGO tables
  +   stbls <- get_ssurgo_tables(lonlat = c(-93, 42))
  + }
  > 
  > proc.time()
     user  system elapsed 
     0.81    0.18    0.96 
Running the tests in 'tests/test_insert_replacement_node.R' failed.
Complete output:
  > ## Testing whether 
  > 
  > 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)
  > 
  > # apsimx_options(warn.versions = FALSE,
  > #                exe.path = "/Applications/APSIM2022.6.7044.0.app/Contents/Resources/bin/Models",
  > #                examples.path = "/Applications/APSIM2022.6.7044.0.app/Contents/Resources/Examples")
  > 
  > run.insert <- get(".run.local.tests", envir = apsimx.options)
  > 
  > #### This does not work at the moment
  > run.insert <- FALSE
  > 
  > tmp.dir <- tempdir()
  > extd.dir <- system.file("extdata", package = "apsimx")
  > 
  > if(run.insert){
  +   
  +   ex.dir <- auto_detect_apsimx_examples()
  +   
  +   #### Test for wheat ####
  +   wheat <- get_apsimx_json(model = "Wheat", wrt.dir = tmp.dir)
  +   
  +   file.copy(file.path(ex.dir, "Wheat.apsimx"), tmp.dir)  
  +   
  +   insert_replacement_node("Wheat.apsimx", 
  +                           src.dir = tmp.dir, 
  +                           wrt.dir = tmp.dir,
  +                           rep.node = wheat)
  +   
  +   sim0 <- apsimx("Wheat-edited.apsimx", src.dir = tmp.dir)
  +   
  +   #### Test for maize ####
  +   maize <- get_apsimx_json(model = "Maize", wrt.dir = tmp.dir)
  +   
  +   file.copy(file.path(ex.dir, "Maize.apsimx"), tmp.dir)  
  +   
  +   insert_replacement_node("Maize.apsimx", 
  +                           src.dir = extd.dir, 
  +                           wrt.dir = tmp.dir,
  +                           rep.node = maize)
  +   
  +   sim1 <- apsimx("Maize-edited.apsimx", src.dir = tmp.dir)
  +   
  +   #### Test for soybean ####
  +   soybean <- get_apsimx_json(model = "Soybean", wrt.dir = tmp.dir)
  +   
  +   file.copy(file.path(ex.dir, "Soybean.apsimx"), tmp.dir)  
  +   
  +   insert_replacement_node("Soybean.apsimx", 
  +                           src.dir = extd.dir, 
  +                           wrt.dir = tmp.dir,
  +                           rep.node = soybean)
  +   
  +   sim2 <- apsimx("Soybean-edited.apsimx", src.dir = tmp.dir)
  +   
  + }
  > 
  > proc.time()
     user  system elapsed 
     0.75    0.18    0.87 
Running the tests in 'tests/test_inspect.R' failed.
Complete output:
  > ## Run a few tests for the examples
  > 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)
  > apsimx_options(warn.versions = FALSE)
  > 
  > ## Run inspect tests
  > 
  > run.inspect.tests <- get(".run.local.tests", envir = apsimx.options)
  > 
  > if(run.inspect.tests) ex.dir <- auto_detect_apsimx_examples()
  > 
  > if(run.inspect.tests){
  +   
  +   ## Barley
  +   i <- "Barley.apsimx"
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Clock")        
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Weather")        
  +   inspect_apsimx(i, src.dir = ex.dir, node = "MicroClimate")  
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "Physical")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "SoilWater")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "SoilWater", parm = "SummerDate")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "SoilWater", parm = "SummerCona")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "Organic")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "InitialWater")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "Chemical")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "SurfaceOrganicMatter")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Crop")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list("Fertilise", NA))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list("Sow on a fixed date", NA))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list("Sow on a fixed date", 1))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list("Sow on a fixed date", 2))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list("Sow on a fixed date", 3))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list("Sow on a fixed date", 4))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list("Sow on a fixed date", 5))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list("Sow on a fixed date", 6))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Report")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Report", parm = "VariableNames")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Report", parm = "EventNames")
  + 
  +   ## Maize
  +   i <- "Maize.apsimx"
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Clock")        
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Weather") 
  +   inspect_apsimx(i, src.dir = ex.dir, node = "MicroClimate")  
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "Physical")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "SoilWater")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "Organic")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "Chemical")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "InitialWater")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "SurfaceOrganicMatter")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Crop")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list('variable', NA))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list('Fertilise', NA))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Report", parm = "VariableNames")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Report", parm = "EventNames")
  +   
  +   ## Oats
  +   i <- "Oats"
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Clock")        
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Weather")   
  +   inspect_apsimx(i, src.dir = ex.dir, node = "MicroClimate")  
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "Water")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "SoilWater")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "SoilWater", parm = "SummerDate")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "Organic")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "Chemical")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "SurfaceOrganicMatter")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Crop")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list('Fert', NA))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list('variable', NA))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list('variable', 1))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list('variable', 2))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list('variable', 3))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list('variable', 4))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list('variable', 5))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list('variable', 6))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list('variable', 7))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list('variable', 8))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list('variable', 9))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Report", parm = "VariableNames")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Report", parm = "EventNames")
  +   
  +   ## OilPalm is good for testing Report
  +   i <- "OilPalm.apsimx"
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Clock")        
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Weather")    
  +   inspect_apsimx(i, src.dir = ex.dir, node = "MicroClimate")  
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "Physical")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "SoilWater")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "SoilWater", parm = "SummerDate")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "Organic")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Soil", soil.child = "Chemical")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "SurfaceOrganicMatter")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list("Palm Management", NA))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Manager", parm = list("Palm Management", 3))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Report")
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Report", parm = list("Annual", NA))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Report", parm = list("Monthly", NA))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Report", parm = list("Annual", "Variable"))
  +   inspect_apsimx(i, src.dir = ex.dir, node = "Report", parm = list("Monthly", "Event"))
  +   
  +   
  + }
  > 
  > run.inspect.print.path.tests <- get(".run.local.tests", envir = apsimx.options)
  > 
  > if(run.inspect.print.path.tests){
  +   
  +   i <- "Barley.apsimx"
  +   #### Clock ####
  +   pp <- inspect_apsimx(i, src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Clock") 
  +     stop("Error in inspect_apsimx, Barley, Clock, print.path")
  +   pp <- inspect_apsimx(i, src.dir = ex.dir, parm = "Start", print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Clock.Start") 
  +     stop("Error in inspect_apsimx, Barley, Start, print.path")
  +   #### Weather ####
  +   pp <- inspect_apsimx(i, node = "Weather", src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Weather") 
  +     stop("Error in inspect_apsimx, Barley, Weather, print.path")
  +   #### Soil - Metadata ####
  +   pp <- inspect_apsimx(i, node = "Soil", src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil") 
  +     stop("Error in inspect_apsimx, Barley, Soil, Metadata, print.path")
  +   pp <- inspect_apsimx(i, node = "Soil", src.dir = ex.dir, 
  +                        parm = "Latitude", print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil.Latitude") ## I think this currently works as expected... ??
  +     stop("Error in inspect_apsimx, Barley, Soil, Metadata, Latitude, print.path")
  +   #### Soil - Physical ####
  +   pp <- inspect_apsimx(i, node = "Soil", soil.child = "Physical",
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil.Physical") 
  +     stop("Error in inspect_apsimx, Barley, Soil, Physical, print.path")
  +   pp <- inspect_apsimx(i, node = "Soil", soil.child = "Physical",
  +                        parm = "DUL", src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil.Physical.DUL") 
  +     stop("Error in inspect_apsimx, Barley, Soil, Physical, DUL, print.path")
  +   pp <- inspect_apsimx(i, node = "Soil", soil.child = "Physical",
  +                        parm = "Barley XF", src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil.Physical.Barley XF") 
  +     stop("Error in inspect_apsimx, Barley, Soil, Physical, Barley XF, print.path")
  +   #### Soil - SoilWater ####
  +   pp <- inspect_apsimx(i, node = "Soil", soil.child = "SoilWater",
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil.SoilWater") 
  +     stop("Error in inspect_apsimx, Barley, Soil, SoilWater, print.path")
  +   pp <- inspect_apsimx(i, node = "Soil", soil.child = "SoilWater", parm = "Salb",
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil.SoilWater.Salb") 
  +     stop("Error in inspect_apsimx, Barley, Soil, SoilWater, SWCON, print.path")
  +   pp <- inspect_apsimx(i, node = "Soil", soil.child = "SoilWater", parm = "SWCON",
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil.SoilWater.SWCON") 
  +     stop("Error in inspect_apsimx, Barley, Soil, SoilWater, SWCON, print.path")
  +   #### Soil - Chemical ####
  +   pp <- inspect_apsimx(i, node = "Soil", soil.child = "Chemical",
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil.Chemical") 
  +     stop("Error in inspect_apsimx, Barley, Soil, Chemical, print.path")
  +   pp <- inspect_apsimx(i, node = "Soil", soil.child = "Chemical", parm = "PH",
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil.Chemical.PH") 
  +     stop("Error in inspect_apsimx, Barley, Soil, Chemical, PH, print.path")
  +   #### Soil - InitialWater ####
  +   pp <- inspect_apsimx(i, node = "Soil", soil.child = "InitialWater",
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil.Water") 
  +     stop("Error in inspect_apsimx, Barley, Soil, InitialWater, print.path")
  +   pp <- inspect_apsimx(i, node = "Soil", soil.child = "InitialWater", parm = "RelativeTo",
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil.Water.RelativeTo") 
  +     stop("Error in inspect_apsimx, Barley, Soil, InitialWater, FractionFull, print.path")
  +   #### Soil - Organic ####
  +   pp <- inspect_apsimx(i, node = "Soil", soil.child = "Organic",
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil.Organic") 
  +     stop("Error in inspect_apsimx, Barley, Soil, Organic, print.path")
  +   pp <- inspect_apsimx(i, node = "Soil", soil.child = "Organic", parm = "Carbon",
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Soil.Organic.Carbon") 
  +     stop("Error in inspect_apsimx, Barley, Soil, Organic, Carbon, print.path")
  +   #### Soil - InitialN ####
  +   ## Note (2023-12-10) Need to change this to NO3, NH3, Urea
  +   # pp <- inspect_apsimx(i, node = "Soil", soil.child = "InitialN",
  +   #                      src.dir = ex.dir, print.path = TRUE)
  +   # if(pp != ".Simulations.Simulation.Field.Soil.InitialN") 
  +   #   stop("Error in inspect_apsimx, Barley, Soil, InitialN, print.path")
  +   #### Soil - CERESSoilTemperature and Nutrient ####
  +   ## There is not much here to test or implement at the moment
  + 
  +   #### Manager ####
  +   pp <- inspect_apsimx(i, node = "Manager", src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field") 
  +     stop("Error in inspect_apsimx, Barley, Manager, print.path")
  +   pp <- inspect_apsimx(i, node = "Manager", parm = list("Fertilise", NA),
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Fertilise at sowing") 
  +     stop("Error in inspect_apsimx, Barley, Manager, Fertilise at sowing, print.path")
  +   pp <- inspect_apsimx(i, node = "Manager", parm = list("Fertilise", 3),
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.Fertilise at sowing.Amount") 
  +     stop("Error in inspect_apsimx, Barley, Manager, Fertilise at sowing, Amount, print.path")
  +   pp <- inspect_apsimx(i, node = "Surface", 
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.SurfaceOrganicMatter") 
  +     stop("Error in inspect_apsimx, Barley, SurfaceOrganicMatter, print.path")
  +   pp <- inspect_apsimx(i, node = "Surface", parm = "InitialResidueMass",
  +                        src.dir = ex.dir, print.path = TRUE)
  +   if(pp != ".Simulations.Simulation.Field.SurfaceOrganicMatter.InitialResidueMass") 
  +     stop("Error in inspect_apsimx, Barley, SurfaceOrganicMatter, InitialResidueMass print.path")
  +   pp <- inspect_apsimx(i, node = "MicroClimate", 
  +                        src.dir = ex.dir, print.path = TRUE)
  +   pp <- inspect_apsimx(i, node = "MicroClimate", parm = "SoilHeatFluxFraction",
  +                        src.dir = ex.dir, print.path = TRUE)
  + }
  > 
  > 
  > inspect.replacement.test <- get(".run.local.tests", envir = apsimx.options)
  > 
  > if(inspect.replacement.test){
  +   
  +   ## Define the highest level
  +   inspect_apsimx_replacement("Factorial", src.dir = ex.dir, 
  +                              root = list("Experiment", 1),
  +                              node = "Base", node.child = "Clock")
  +   ## inspect_apsimx version
  +   inspect_apsimx("Factorial.apsimx", src.dir = ex.dir,
  +                  root = c("Experiment", "Base"),
  +                  node = "Clock")
  +   
  +   inspect_apsimx_replacement("Factorial", src.dir = ex.dir, 
  +                              root = list("Experiment", 1),
  +                              node = "Base", node.child = "Weather")
  +   
  +   ## inspect_apsimx version
  +   inspect_apsimx("Factorial.apsimx", src.dir = ex.dir,
  +                  root = c("Experiment", "Base"),
  +                  node = "Weather")
  +   
  +   inspect_apsimx_replacement("Factorial", src.dir = ex.dir, 
  +                              root = list("Experiment", 1),
  +                              node = "Base", node.child = "Field",
  +                              node.subchild = "Soil",
  +                              display.available = TRUE)
  +   
  +   ## inspect_apsimx version
  +   inspect_apsimx("Factorial.apsimx", src.dir = ex.dir,
  +                  root = c("Experiment", "Base"),
  +                  node = "Soil")
  +   
  +   ## If we want to look at the second Factorial 'Experiment'
  +   inspect_apsimx_replacement("Factorial", src.dir = ex.dir, 
  +                              root = list("Experiment", 2),
  +                              node = "Base", node.child = "Field",
  +                              node.subchild = "Soil",
  +                              display.available = TRUE)
  +   
  +   ## Look at Water
  +   inspect_apsimx_replacement("Factorial", src.dir = ex.dir, 
  +                              root = list("Experiment", 2),
  +                              node = "Base", node.child = "Field",
  +                              node.subchild = "Soil",
  +                              node.subsubchild = "Water",
  +                              display.available = TRUE)
  +   
  +   ## For a specific parameter
  +   inspect_apsimx_replacement("Factorial", src.dir = ex.dir, 
  +                              root = list("Experiment", 2),
  +                              node = "Base", node.child = "Field",
  +                              node.subchild = "Soil",
  +                              node.subsubchild = "Water",
  +                              parm = "Depth")
  + }
  > 
  > inspect.replacement.test2 <- get(".run.local.tests", envir = apsimx.options)
  > 
  > extd.dir <- system.file("extdata", package = "apsimx")
  > 
  > if(inspect.replacement.test2){
  +   
  +   ## Testing inspect_apsimx on MaizeSoybean.apsimx
  +   pp <- inspect_apsimx("MaizeSoybean.apsimx", src.dir = extd.dir,
  +                        node = "Weather",
  +                        root = "SimulationSoybean",
  +                        parm = "FileName",
  +                        print.path = TRUE)
  +   
  +   if(pp != ".Simulations.SimulationSoybean.Weather.FileName")
  +     stop("pp does not match for inspect_apsimx MaizeSoybean.apsimx root = SimulationSoybean", call. = FALSE)
  +   
  +   pp <- inspect_apsimx_replacement("MaizeSoybean.apsimx", src.dir = extd.dir,
  +                                    root = "SimulationSoybean", 
  +                                    node = "Weather", parm = "FileName", print.path = TRUE)
  +   
  +   if(pp != ".Simulations.SimulationSoybean.Weather.FileName")
  +     stop("pp does not match for inspect_apsimx_replacement MaizeSoybean.apsimx root = SimulationSoybean", call. = FALSE)
  +   
  +   ## Looking at values within Leaf
  +   inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                              src.dir = extd.dir, 
  +                              node = "Soybean",
  +                              display.available = TRUE)
  +   
  +   inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                              src.dir = extd.dir, 
  +                              node = "Soybean",
  +                              node.child = "Leaf",
  +                              display.available = TRUE)
  +   
  +   ## We can look at parameters at this level
  +   inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                              src.dir = extd.dir, 
  +                              node = "Soybean",
  +                              node.child = "Leaf",
  +                              parm = "Albedo")
  +                              
  +   inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                              src.dir = extd.dir, 
  +                              node = "Soybean",
  +                              node.child = "Leaf",
  +                              parm = "Gsmax350")
  +                              
  +   inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                              src.dir = extd.dir, 
  +                              node = "Soybean",
  +                              node.child = "Leaf",
  +                              parm = "R50")
  +   
  +   inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                              src.dir = extd.dir, 
  +                              node = "Soybean",
  +                              node.child = "Leaf",
  +                              node.subchild = "Photosynthesis",
  +                              node.subsubchild = "RUE")
  +   
  +   inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                              src.dir = extd.dir, 
  +                              node = "Soybean",
  +                              node.child = "Leaf",
  +                              node.subchild = "Photosynthesis",
  +                              node.subsubchild = "RUE",
  +                              parm = "FixedValue")
  + 
  +   ## Soybean Cultivars
  +   pp <- inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                                    src.dir = extd.dir, 
  +                                    node = "Soybean",
  +                                    node.child = "Cultivars",
  +                                    node.subchild = "USA",
  +                                    node.subsubchild = "PioneerP22T61_MG22",
  +                                    parm = "Vegetative.Target.FixedValue",
  +                                    print.path = TRUE)
  +   
  +   if(pp != ".Simulations.Replacements.Soybean.Cultivars.USA.PioneerP22T61_MG22.Vegetative.Target.FixedValue") 
  +     stop("Error in inspect_apsimx_replacement, MaizeSoybean, PioneerP22T61_MG22, Vegetative.Target.FixedValue, print.path")
  + 
  +   pp <- inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                                    src.dir = extd.dir, 
  +                                    node = "Soybean",
  +                                    node.child = "Cultivars",
  +                                    node.subchild = "USA",
  +                                    node.subsubchild = "PioneerP22T61_MG22",
  +                                    parm = "EarlyFlowering",
  +                                    print.path = TRUE)
  +   
  +   if(pp != ".Simulations.Replacements.Soybean.Cultivars.USA.PioneerP22T61_MG22.EarlyFlowering") 
  +     stop("Error in inspect_apsimx_replacement, MaizeSoybean, PioneerP22T61_MG22, EarlyFlowering, print.path")
  +   
  +   ## Testing the root
  +   inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                              src.dir = extd.dir, 
  +                              root = "SimulationSoybean",
  +                              node = "Weather",
  +                              parm = "FileName")
  + 
  +   inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                              src.dir = extd.dir, 
  +                              root = "SimulationMaize",
  +                              node = "Weather",
  +                              parm = "FileName")
  +   
  +   ## WheatRye version
  +   inspect_apsimx_replacement("WheatRye.apsimx", src.dir = extd.dir,
  +                              node = "Wheat", node.child = "Cultivars",
  +                              node.subchild = "USA", node.subsubchild = "Yecora")
  +   
  +   ## Now with parameter
  +   inspect_apsimx_replacement("WheatRye.apsimx", src.dir = extd.dir,
  +                              node = "Wheat", node.child = "Cultivars",
  +                              node.subchild = "USA", node.subsubchild = "Yecora",
  +                              parm = "MinimumLeafNumber")
  +   ## This only works for the first one
  +   inspect_apsimx_replacement("WheatRye.apsimx", src.dir = extd.dir,
  +                              node = "Wheat", node.child = "Cultivars",
  +                              node.subchild = "USA", node.subsubchild = "Yecora",
  +                              parm = "Vrn")
  +                              
  + }
  >  
  > 
  > inspect.replacement.test.parm.path <- get(".run.local.tests", envir = apsimx.options)
  > 
  > if(inspect.replacement.test.parm.path){
  +   
  +   pp <- inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                                    src.dir = extd.dir, 
  +                                    print.path = TRUE)
  +   
  +   pp <- inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                                    src.dir = extd.dir, 
  +                                    node = "Soybean",
  +                                    print.path = TRUE)
  +   
  +   pp <- inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                                    src.dir = extd.dir, 
  +                                    node = "Soybean",
  +                                    node.child = "Leaf",
  +                                    print.path = TRUE)
  +   
  +   pp <- inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                                    src.dir = extd.dir, 
  +                                    node = "Soybean",
  +                                    node.child = "Leaf",
  +                                    parm = "Albedo",
  +                                    print.path = TRUE)
  +   
  +   pp <- inspect_apsimx_replacement("MaizeSoybean.apsimx", 
  +                                    src.dir = extd.dir, 
  +                                    node = "Soybean",
  +                                    node.child = "Leaf",
  +                                    parm = "Gsmax350",
  +                                    print.path = TRUE)
  +   
  +   ### Testing replacement with new simulations (Dec 2023)
  +   ### Not normal testing as these files are not distributed with APSIM
  +   ### In the future, I will create some and distribute with the package
  +   
  +   if(FALSE){
  +     
  +     csm.dir <- "~/Desktop/csm/lab_05"
  +     
  +     pp1 <- inspect_apsimx_replacement("MaizeSoybean_replacement.apsimx",
  +                                       src.dir = csm.dir,
  +                                       node = "Maize",
  +                                       node.child = "Leaf",
  +                                       node.subchild = "Photosynthesis",
  +                                       node.subsubchild = "RUE",
  +                                       parm = "FixedValue",
  +                                       display.available = FALSE,
  +                                       print.path = TRUE)
  +     
  +     ### Need to look at whether I can edit this
  +     
  +     
  +   }
  + }
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.92    0.10    1.01 
Running the tests in 'tests/test_inspect_apsim_factorial.R' failed.
Complete output:
  > ## Testing the factorial feature for inspect_apsim
  > 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)
  > 
  > run.factorial.apsim <- FALSE
  > 
  > extd.dir <- system.file("extdata", package = "apsimx")
  > 
  > tmp.dir <- tempdir()
  > 
  > if(run.factorial.apsim){
  +   
  +   ## There are two folders in 'maize-factorial'
  +   inspect_apsim("maize-factorial.apsim", src.dir = extd.dir,
  +                 node = "Clock", parm = "start_date",
  +                 root = "IA-CC_Canisteo_No-Cover",
  +                 print.path = TRUE)
  +   
  +   inspect_apsim("maize-factorial.apsim", src.dir = extd.dir,
  +                 node = "Clock", parm = "start_date",
  +                 root = "IA-CC_Canisteo_Cover",
  +                 print.path = TRUE)
  +   
  +   ## Edit them
  +   pp1 <- inspect_apsim("maize-factorial.apsim", src.dir = extd.dir,
  +                         node = "Clock", parm = "start_date",
  +                         root = "IA-CC_Canisteo_No-Cover",
  +                         print.path = TRUE)
  +   
  +   edit_apsim("maize-factorial.apsim", 
  +              src.dir = extd.dir,
  +              wrt.dir = tmp.dir,
  +              node = "Other", 
  +              parm.path = pp1, 
  +              value = "01/02/1999")
  +   
  +   inspect_apsim("maize-factorial-edited.apsim", 
  +                 src.dir = tmp.dir,
  +                 node = "Clock", parm = "start_date",
  +                 root = "IA-CC_Canisteo_No-Cover",
  +                 print.path = TRUE)
  +   
  +   ## Second example
  +   pp2 <- inspect_apsim("maize-factorial.apsim", src.dir = extd.dir,
  +                        node = "Clock", parm = "start_date",
  +                        root = "IA-CC_Canisteo_No-Cover",
  +                        print.path = TRUE)
  +  
  +   edit_apsim("maize-factorial.apsim", 
  +              src.dir = extd.dir,
  +              wrt.dir = tmp.dir,
  +              node = "Other", 
  +              parm.path = pp2, 
  +              value = "01/02/2009")
  +   
  +   inspect_apsim("maize-factorial-edited.apsim", 
  +                 src.dir = tmp.dir,
  +                 node = "Clock", parm = "start_date",
  +                 root = "IA-CC_Canisteo_No-Cover",
  +                 print.path = TRUE)
  +   
  +   
  + }
  > 
  > proc.time()
     user  system elapsed 
     0.73    0.21    0.93 
Running the tests in 'tests/test_inspect_apsim_xml.R' failed.
Complete output:
  > ## Testing inspect for Classic
  > 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)
  > 
  > apsimx_options(warn.versions = FALSE)
  > 
  > ## Run inspect tests
  > ## inspect_apsim returns relative paths (an xpath expression), but still a character
  > ## inspect_apsim_xml returns absolute paths 
  > 
  > run.inspect.tests <- get(".run.local.tests", envir = apsimx.options)
  > 
  > if(run.inspect.tests){
  +   
  +   extd.dir <- system.file("extdata", package = "apsimx")
  +   ## Clock and clock path
  +   inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Clock")
  +   pp <- inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Clock", 
  +                       parm = "start", print.path = TRUE)
  +   if(pp != ".//clock/start_date") stop("Clock path is incorrect")
  +   inspect_apsim_xml("Millet.apsim", src.dir = extd.dir, parm = pp)
  +   ## Weather and weather path
  +   inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Weather")
  +   pp <- inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Weather", 
  +                       parm = "filename", print.path = TRUE)
  +   if(pp != ".//metfile/filename") stop("Weather path is incorrect")
  +   inspect_apsim_xml("Millet.apsim", src.dir = extd.dir, parm = pp)
  +   ## Soil Metadata
  +   inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil", soil.child = "Metadata")
  +   pp <- inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil",
  +                       soil.child = "Metadata", parm = "LocalName", print.path = TRUE)
  +   if(pp != ".//Soil/LocalName") stop("Soil Metadata path is incorrect")
  +   inspect_apsim_xml("Millet.apsim", src.dir = extd.dir, parm = pp)
  +   ## Soil Water
  +   inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil", soil.child = "Water")
  +   pp <- inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil",
  +                       soil.child = "Water", parm = c("Barley", "KL"), print.path = TRUE)
  +   if(pp != ".//Soil/Water/SoilCrop[@name='Barley']/KL") stop("Soil Water KL path is incorrect")
  +   
  +   inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil", soil.child = "Water",
  +                 parm = "SWCON")
  +   pp <-   inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil", soil.child = "Water",
  +                         parm = "SWCON", print.path = TRUE)
  +   if(pp != ".//Soil/SoilWater/SWCON") stop("Soil Water SWCON path is incorrect")
  +   ## In this case there are multiple elements for KL, so the path needs to be different
  +   ## If we want to identify a single value. There are many KLs, one for each crop, and there 
  +   ## are 8 crops here
  +   inspect_apsim_xml("Millet.apsim", src.dir = extd.dir, parm = ".//SoilCrop[@name='Barley']/KL/double[1]")
  +   pp <- inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil",
  +                       soil.child = "Water", parm = "SummerCona", print.path = TRUE)
  +   if(pp != ".//Soil/SoilWater/SummerCona") stop("Soil Water SummerCona path is incorrect")
  +   inspect_apsim_xml("Millet.apsim", src.dir = extd.dir, parm = pp)
  +   ## Soil Organic Matter
  +   inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil", soil.child = "OrganicMatter")
  +   pp <- inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil",
  +                       soil.child = "OrganicMatter", parm = "OC", print.path = TRUE)
  +   if(pp != ".//Soil/SoilOrganicMatter/OC") stop("Soil Organic Matter OC path is incorrect")
  +   ## In this case there are multiple values of OC, so we need to select one
  +   inspect_apsim_xml("Millet.apsim", src.dir = extd.dir, parm = paste0(pp, "/double[1]"))
  +   ### Analysis
  +   inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil", soil.child = "Analysis")
  +   pp <- inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil",
  +                       soil.child = "Analysis", parm = "PH", print.path = TRUE)
  +   if(pp != ".//Soil/Analysis/PH") stop("Soil Analysis PH path is incorrect")
  +   inspect_apsim_xml("Millet.apsim", src.dir = extd.dir, parm = paste0(pp, "/double[1]"))
  +   ## Initial Water
  +   inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil", soil.child = "InitialWater")
  +   pp <- inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil",
  +                       soil.child = "InitialWater", parm = "FractionFull", print.path = TRUE)
  +   if(pp != ".//Soil/InitialWater/FractionFull") stop("Soil InitialWater FractionFull path is incorrect")
  +   inspect_apsim_xml("Millet.apsim", src.dir = extd.dir, parm = pp)
  +   ## Sample
  +   inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil", soil.child = "Sample")
  +   pp <- inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Soil",
  +                       soil.child = "Sample", parm = "NO3", print.path = TRUE)
  +   inspect_apsim_xml("Millet.apsim", src.dir = extd.dir, parm = paste0(pp, "/double[1]"))
  +   ## Surface Organic Matter
  +   inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "SurfaceOrganicMatter")
  +   pp <- inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "SurfaceOrganicMatter",
  +                       parm = "type", print.path = TRUE)
  +   inspect_apsim_xml("Millet.apsim", src.dir = extd.dir, parm = pp)
  +   ## Crop or Manager
  +   inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Crop", parm = list("sow",NA)) 
  +   ## Crop with Parameter, This returns the full absolute path
  +   pp <- inspect_apsim("Millet.apsim", src.dir = extd.dir, node = "Crop", parm = list("sow",7),
  +                       print.path = TRUE)
  +   ## Strangely the full path does not work here, but just "cultivar" does
  +   inspect_apsim_xml("Millet.apsim", src.dir = extd.dir, parm = "cultivar")
  +   
  + }
  > 
  > proc.time()
     user  system elapsed 
     0.89    0.18    1.07 
Running the tests in 'tests/test_inspect_apsimx_json.R' failed.
Complete output:
  > ### Testing the spanking new inspect_apsimx_json
  > 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)
  > 
  > run.inspect.apsimx.json <- FALSE
  > 
  > if(run.inspect.apsimx.json){
  +   
  +   extd.dir <- system.file("extdata", package = "apsimx")
  +   
  +   inspect_apsimx_json("Maize.apsimx", src.dir = extd.dir, parm = "^Version")
  +   
  +   inspect_apsimx_json("Maize.apsimx", src.dir = extd.dir, parm = "Version")
  +   
  +   inspect_apsimx_json("Maize.apsimx", src.dir = extd.dir, parm = "ApsimVersion")
  +   
  +   inspect_apsimx_json("Maize.apsimx", src.dir = extd.dir, parm = "Clock")
  +   
  +   inspect_apsimx_json("Maize.apsimx", src.dir = extd.dir, parm = "Soil") 
  +   
  +   inspect_apsimx_json("Maize.apsimx", src.dir = extd.dir, parm = "Soil") 
  +   
  +   inspect_apsimx_json("Maize.apsimx", src.dir = extd.dir, parm = "Dekalb") 
  +   
  +   inspect_apsimx_json("Maize.apsimx", src.dir = extd.dir, parm = "10-jan") 
  + 
  +   ## These parameters do not return a single path
  +   ## Ideally, I would be able to either return multiple paths or use
  +   ## a jsonpath for the search instead of a single keyword
  +   inspect_apsimx_json("Maize.apsimx", src.dir = extd.dir, parm = "Water") 
  +   inspect_apsimx_json("Maize.apsimx", src.dir = extd.dir, parm = "Cultivar") 
  + }
  > 
  > proc.time()
     user  system elapsed 
     0.84    0.12    0.95 
Running the tests in 'tests/test_vignette.R' failed.
Complete output:
  > ## These are tests that I will run to reproduce the part of the vignette
  > ## That depends on APSIM-X. In this way the vignette can be build independently
  > ## of APSIM-X, but the testing side-effect of the vignette is still present
  > 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)
  > apsimx_options(warn.versions = FALSE)
  > 
  > extd.dir <- system.file("extdata", package = "apsimx")
  > 
  > run.vignette <- get(".run.local.tests", envir = apsimx.options)
  > 
  > tmp.dir <- tempdir()
  > 
  > if(run.vignette){
  + 
  +   ## Copy 'Maize.apsimx' to 'tmp.dir'
  +   ex.dir <- auto_detect_apsimx_examples()
  +   file.copy(from = paste0(ex.dir,"/","Maize.apsimx"),
  +             to = tmp.dir, copy.mode = FALSE)
  +   maize <- apsimx("Maize.apsimx", src.dir = tmp.dir)
  + 
  +   ## Running 'Wheat' example
  +   file.copy(from = paste0(ex.dir,"/","Wheat.apsimx"),
  +             to = tmp.dir, copy.mode = FALSE)
  +   wheat <- apsimx("Wheat.apsimx", src.dir = tmp.dir)
  + 
  +   ## Running 'MaizeSoybean' example
  +   file.copy(from = paste0(extd.dir,"/","Ames.met"),
  +             to = tmp.dir)
  +   file.copy(from = paste0(extd.dir,"/","MaizeSoybean.apsimx"),
  +             to = tmp.dir)
  +   maize.soy <- apsimx("MaizeSoybean.apsimx", src.dir = tmp.dir)
  + 
  +   ## The code below should only be run from my laptop and only when a new
  +   ## version of APSIM-X is released
  +   ## This updates the 'Wheat' and 'Maize' example files in case they have
  +   ## changed
  + 
  +   aiu <- apsim_version(which = "inuse", verbose = FALSE)
  + 
  +   ## Need to change this for new versions of APSIM-X
  +   ## apsimx.new.version <- as.numeric(strsplit(aiu, ".", fixed = TRUE)[[1]][4])
  + 
  +   my.laptop <- grepl("fernandomiguez", Sys.info()[["user"]])
  +   ## This is only for my laptop
  +   if(my.laptop && FALSE){
  +     my.extd <- "~/Dropbox/apsimx/inst/extdata"
  +     file.copy(from = paste0(ex.dir,"/","Maize.apsimx"),
  +               to = my.extd, copy.mode = FALSE, 
  +               overwrite = TRUE)
  +     file.copy(from = paste0(ex.dir,"/","Wheat.apsimx"),
  +               to = my.extd, copy.mode = FALSE,
  +               overwrite = TRUE)
  +   }
  + }
  > 
  > proc.time()
     user  system elapsed 
     0.76    0.12    0.87