Package {apsimwise}


Title: Unified Access to the APSIMWISE Ecosystem
Version: 0.1.0
Description: Provides a unified interface to R packages supporting the Agricultural Production Systems sIMulator (APSIM), crop modelling, weather analysis, and agricultural decision support. It simplifies installation and loading of related packages and provides consistent user-facing functions across multiple crop types.
License: MIT + file LICENSE
Encoding: UTF-8
Depends: R (≥ 4.1.0)
Imports: rapsimng (≥ 0.6.0), rapsimng.wheat (≥ 0.1.0), rapsimng.lupin (≥ 0.1.0), rapsimng.chickpea (≥ 0.1.0), rapsimng.fababean (≥ 0.1.0), rapsimng.lentil (≥ 0.1.0), rapsimng.canola (≥ 0.1.0), tidyweather (≥ 0.3.2)
Suggests: testthat (≥ 3.0.0), dplyr, knitr, quarto, ggplot2
Config/testthat/edition: 3
URL: https://apsimwise.bangyou.me/, https://github.com/byzheng/apsimwise
BugReports: https://github.com/byzheng/apsimwise/issues
Config/roxygen2/version: 8.1.0
VignetteBuilder: knitr, quarto
NeedsCompilation: no
Packaged: 2026-10-01 08:19:48 UTC; zhe00a
Author: Bangyou Zheng [aut, cre]
Maintainer: Bangyou Zheng <zheng.bangyou@gmail.com>
Repository: CRAN
Date/Publication: 2026-10-13 14:50:13 UTC

Access crop-specific model options

Description

Returns the options manager associated with a crop. The returned object can be used to inspect and modify crop-specific parameters such as thermal time and vernalisation responses.

Usage

crop(name)

Arguments

name

Character string specifying the crop name. Supported crops include (case-insensitive): "wheat", "canola", "chickpea", "lupin", "fababean", and "lentil".

Value

An options manager object created by optree::create_options_manager().

Examples

# Get the lentil options manager
l <- crop("lentil")

# View all options
l$get()

# Retrieve thermal time parameters
l$get("phenology.thermal_time")

# Modify an option
l$set(
  "phenology.thermal_time" =
  list(
    x = c(0, 25, 35),
    y = c(0, 25, 0)
  )
)


Objects exported from other packages

Description

These objects are imported from other packages. Follow the links below to see their documentation.

rapsimng

append_model(), insert_model(), insert_models(), list_report(), read_apsimx(), read_report(), remove_model(), replace_model(), run_models(), search_node(), search_path(), write_apsimx()

tidyweather

day_length(), read_weather()


Calculate thermal time for a crop

Description

Calculate thermal time for a crop

Usage

thermal_time(..., crop)

Arguments

...

Arguments passed to the selected crop's thermal time function.

crop

The crop model to use. Supported crops are wheat, canola, chickpea, lupin, fababean, and lentil.

Value

A vector of thermal time values for the specified crop.

Examples


library(apsimwise)
# Example weather data
mint <- c(0, 10)
maxt <- c(30, 40)
date <- as.Date(c("2024-01-01", "2024-01-02"))

# Use default lupin parameters
thermal_time(
  mint,
  maxt,
  date = date,
  lat = -27,
  crop = "lupin"
)

# Modify the global lupin thermal time response for all following calculations
crop("lupin")$set(
  "phenology.thermal_time" =
  list(
    x = c(0, 25, 35),
    y = c(0, 25, 0)
  )
)
thermal_time(
  mint,
  maxt,
  date = date,
  lat = -27,
  crop = "lupin"
)

# Then the parameters can be reset
crop("lupin")$reset()


# Override thermal time parameters for a single call
thermal_time(
  mint,
  maxt,
  date = date,
  lat = -27,
  crop = "lupin",
  x_temp = c(0, 25, 35),
  y_temp = c(0, 25, 0)
)

# Calculate thermal time from a weather file
met_file <- system.file("extdata/ppd_72150.met", package = "tidyweather")
# Read weather records
records <- read_weather(met_file)
# Calculate thermal time for lupin using tidyverse ways
library(dplyr)
records |>
    mutate(
        tt = thermal_time(
            mint = mint,
            maxt = maxt,
            date = date,
            latitude = latitude[1],
            crop = "lupin"
        )
    ) |>
    select(name, date, mint, maxt, tt)
# Calculate thermal time for lupin grouped by year and site if there are multiple sites
# Create some fake data for a second site
records2 <- records |>
    mutate(
        name = "site2",
        mint = mint + 1,
        maxt = maxt + 1,
        latitude = latitude - 10
    ) |>
    bind_rows(records)
# Calculate thermal time for lupin grouped by site
records2 |>
    group_by(name) |>
    mutate(
        tt = thermal_time(
            mint = mint,
            maxt = maxt,
            date = date,
            latitude = latitude[1],
            crop = "lupin"
        )
    ) |>
    select(name, date, mint, maxt, tt)

Calculate vernalisation days for a crop

Description

Calculate vernalisation days for a crop

Usage

vernalisation_days(..., crop)

Arguments

...

Arguments passed to the selected crop's vernalisation days function.

crop

The crop model to use. Supported crops are canola, chickpea, lupin, fababean, and lentil.

Value

A vector of vernalisation days for the specified crop.

Examples

mint <- c(0, 10)
maxt <- c(30, 40)
vernalisation_days(mint, maxt, crop = "lupin")