# rapsimng [![](https://www.r-pkg.org/badges/version/rapsimng?color=green)](https://cran.r-project.org/package=rapsimng) ![R-CMD-check](https://github.com/byzheng/rapsimng/workflows/R-CMD-check/badge.svg) [![](http://cranlogs.r-pkg.org/badges/grand-total/rapsimng?color=green)](https://cran.r-project.org/package=rapsimng) [![](http://cranlogs.r-pkg.org/badges/last-month/rapsimng?color=green)](https://cran.r-project.org/package=rapsimng) [![](http://cranlogs.r-pkg.org/badges/last-week/rapsimng?color=green)](https://cran.r-project.org/package=rapsimng) [rapsimng](https://rapsimng.bangyou.me) package is designed to modify and run the \*.apsimx simulations using R in [APSIM Next Generation](https://www.apsim.info/). ## Features - Find elements in the \*.apsimx file ## Crop-specific resources For crop-specific functions and additional resources, please refer to: - [Wheat](https://wheat.rapsimng.bangyou.me/) - [Canola](https://canola.rapsimng.bangyou.me/) ## Installation Install from CRAN. ``` r install.packages('rapsimng') ``` Install the developing version from [Github](https://github.com/byzheng/rapsimng). ``` r remotes::install_github('byzheng/rapsimng') ``` ## Read APSIMX file The `wheat.apsimx` in the validation dataset of APSIM NG is used as an example. Function `read_apsimx` is used to read `*.apsimx` file through [`jsonlite::read_json`](https://jeroen.r-universe.dev/jsonlite/reference/read_json.html) and returns as a list. ``` r # Read Wheat.apsimx file with `read_apsimx` which returns a list of json results. file <- system.file("extdata/wheat.apsimx", package = "rapsimng") m <- read_apsimx(file) ``` ## Search by of APSIM NG A node in the apsimx file can be found using the path specification in APSIM NG. ``` r potential <- search_path(m, path = '[Structure].BranchingRate.PotentialBranchingRate.Vegetative.PotentialBranchingRate') potential ``` ## Modify a found model ``` r new_model <- potential$node new_model$XProperty <- 'NewVariable' ``` ## Replace the new model ``` r new <- replace_model(m, potential$path, new_model) ``` ## Save into a new apsimx file ``` r write_apsimx(new, tempfile(fileext = '.json')) ``` ## Run apsimx file A function `run_models` is wrapped for APSIM NG `Models.exe` in the command line and can be called to run apsimx files. See [APSIM website](https://apsimnextgeneration.netlify.app/) for documentation. # Package index ## All functions - [`append_model()`](https://rapsimng.bangyou.me/reference/append_model.md) : append a model into apsimx - [`disable_models()`](https://rapsimng.bangyou.me/reference/disable_models.md) : Disable models in apsimx - [`default_frost_heat_params()`](https://rapsimng.bangyou.me/reference/frost_heat_damage.md) [`stage_sens_frost()`](https://rapsimng.bangyou.me/reference/frost_heat_damage.md) [`stage_sens_heat()`](https://rapsimng.bangyou.me/reference/frost_heat_damage.md) [`temp_damage_frost()`](https://rapsimng.bangyou.me/reference/frost_heat_damage.md) [`temp_damage_heat()`](https://rapsimng.bangyou.me/reference/frost_heat_damage.md) [`daily_damage_frost()`](https://rapsimng.bangyou.me/reference/frost_heat_damage.md) [`daily_damage_heat()`](https://rapsimng.bangyou.me/reference/frost_heat_damage.md) [`daily_damage_frost_heat()`](https://rapsimng.bangyou.me/reference/frost_heat_damage.md) [`cum_damage_frost()`](https://rapsimng.bangyou.me/reference/frost_heat_damage.md) [`cum_damage_heat()`](https://rapsimng.bangyou.me/reference/frost_heat_damage.md) [`cum_damage_frost_heat()`](https://rapsimng.bangyou.me/reference/frost_heat_damage.md) [`calc_daily_damage_frost_heat()`](https://rapsimng.bangyou.me/reference/frost_heat_damage.md) [`calc_cum_damage_frost_heat()`](https://rapsimng.bangyou.me/reference/frost_heat_damage.md) : Frost and Heat Damage Functions - [`get_cultivar()`](https://rapsimng.bangyou.me/reference/get_cultivar.md) : Get all cultivar parameters in a model - [`get_experiment()`](https://rapsimng.bangyou.me/reference/get_experiment.md) : Get an experiment node by name - [`get_metfile()`](https://rapsimng.bangyou.me/reference/get_metfile.md) : Get the met file name for an experiment - [`get_parent()`](https://rapsimng.bangyou.me/reference/get_parent.md) : Get the parent node from a path - [`get_pawc()`](https://rapsimng.bangyou.me/reference/get_pawc.md) : Estimate Plant Available Water Capacity (PAWC) from an apsimx file - [`get_simulations()`](https://rapsimng.bangyou.me/reference/get_simulations.md) : Get simulations for a factorial experiment - [`insert_model()`](https://rapsimng.bangyou.me/reference/insert_model.md) : Insert a model into apsimx - [`insert_models()`](https://rapsimng.bangyou.me/reference/insert_models.md) : Insert models into apsimx - [`install_apsimng()`](https://rapsimng.bangyou.me/reference/install_apsimng.md) : Install ApsimNG Software - [`keep_simulations()`](https://rapsimng.bangyou.me/reference/keep_simulations.md) : Keep simulations for a factorial experiment - [`list_report()`](https://rapsimng.bangyou.me/reference/list_report.md) : List all reports in the database - [`log_level()`](https://rapsimng.bangyou.me/reference/log_level.md) : Set the log level of apsimx file - [`minimum_apsimng()`](https://rapsimng.bangyou.me/reference/minimum_apsimng.md) : Create the minimum requirements to run an APSIM Next Generation - [`new_cultivar()`](https://rapsimng.bangyou.me/reference/new_cultivar.md) : Generate new cultivars with parameter which can be used in Replacements - [`new_model()`](https://rapsimng.bangyou.me/reference/new_model.md) : Create a new model - [`read_apsimx()`](https://rapsimng.bangyou.me/reference/read_apsimx.md) : Read APSIMX file - [`read_report()`](https://rapsimng.bangyou.me/reference/read_report.md) : Read apsimx database in db file format - [`remove_model()`](https://rapsimng.bangyou.me/reference/remove_model.md) : Remove a model with new values - [`replace_model()`](https://rapsimng.bangyou.me/reference/replace_model.md) : Replace a model with new values - [`run_models()`](https://rapsimng.bangyou.me/reference/run_models.md) : Run apsimx file using Models.exe - [`search_node()`](https://rapsimng.bangyou.me/reference/search_node.md) : Find element(s) in apsimx file - [`search_path()`](https://rapsimng.bangyou.me/reference/search_path.md) : Find a model in the apsimx file using specified path - [`set_parameter_value()`](https://rapsimng.bangyou.me/reference/set_parameter_value.md) : Set a parameter with a new value - [`split_apsimx()`](https://rapsimng.bangyou.me/reference/split_apsimx.md) : Split an APSIMX file into separate simulations except cultivar - [`test_apsimx()`](https://rapsimng.bangyou.me/reference/test_apsimx.md) : Test whether all files under published folder of apsimx are required - [`update_cultivar()`](https://rapsimng.bangyou.me/reference/update_cultivar.md) : Title Update the cultivar parameters - [`with_apsimx()`](https://rapsimng.bangyou.me/reference/with_apsimx.md) : Run APSIM Next Generation Simulations in a Temporary Folder - [`write_apsimx()`](https://rapsimng.bangyou.me/reference/write_apsimx.md) : Write APSIMX file # Articles ### All vignettes - [Modify apsimx file](https://rapsimng.bangyou.me/articles/modify.md): - [Generate apsimx file for sensitivity analysis](https://rapsimng.bangyou.me/articles/sensitivity.md):