Skip to content

Commit

Permalink
Fixing various issues with rcmdcheck
Browse files Browse the repository at this point in the history
- unused packages
- function documentation
  • Loading branch information
dfalster committed Jun 19, 2024
1 parent c609a21 commit 1b810de
Show file tree
Hide file tree
Showing 45 changed files with 601 additions and 502 deletions.
3 changes: 0 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ Imports:
R6,
loggr,
crayon,
nleqslv,
BB,
magrittr,
tibble,
rlang,
Expand All @@ -46,7 +44,6 @@ Suggests:
rmarkdown,
markdown,
bench,
dplyr,
ggplot2,
ggridges,
patchwork,
Expand Down
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(resource_compensation_point,Plant)
S3method(validate,Parameters)
export("%>%")
export(Control)
export(Disturbance_Regime)
Expand Down Expand Up @@ -32,7 +33,6 @@ export(K93_Strategy)
export(K93_fixed_environment)
export(K93_hyperpar)
export(K93_make_environment)
export(K93_test_environment)
export(No_Disturbance)
export(NodeSchedule)
export(TF24_Environment)
Expand All @@ -43,7 +43,6 @@ export(TF24_fixed_environment)
export(TF24_generate_stand_report)
export(TF24_hyperpar)
export(TF24_make_environment)
export(TF24_test_environment)
export(Weibull_Disturbance_Regime)
export(build_schedule)
export(environment_type)
Expand Down
13 changes: 6 additions & 7 deletions R/RcppR6.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Generated by RcppR6: do not edit by hand
## Version: 0.2.4
## Hash: 1e61b714fa073aff744206eaac010b91
## Hash: 1c60048bc1d88826061cc8bb250fbbc8

##' @importFrom Rcpp evalCpp
##' @importFrom R6 R6Class
Expand Down Expand Up @@ -5829,9 +5829,10 @@ StochasticPatchRunner <- function(T, E) {
ret
}

##' FF16_Environment object
##' @param light_availability_spline_rescale_usually whether to rescale intervals when estimating light environment
##' Create an FF16_Environment object.
##' @param soil_number_of_depths Number of soil layers to include
##' @param light_availability_spline_rescale_usually whether to rescale intervals when estimating light environment
##' @rdname FF16_Environment
##' @export
`FF16_Environment` <- function(light_availability_spline_rescale_usually, soil_number_of_depths) {
FF16_Environment__ctor(light_availability_spline_rescale_usually, soil_number_of_depths)
Expand Down Expand Up @@ -5945,7 +5946,7 @@ StochasticPatchRunner <- function(T, E) {
ret
}

##' K93_Environment object
##' @rdname FF16_Environment
##' @export
`K93_Environment` <- function() {
K93_Environment__ctor()
Expand Down Expand Up @@ -6066,9 +6067,7 @@ StochasticPatchRunner <- function(T, E) {
ret
}

##' TF24_Environment object
##' @param light_availability_spline_rescale_usually whether to rescale intervals when estimating light environment
##' @param soil_number_of_depths Number of soil layers to include
##' @rdname FF16_Environment
##' @export
`TF24_Environment` <- function(light_availability_spline_rescale_usually, soil_number_of_depths) {
TF24_Environment__ctor(light_availability_spline_rescale_usually, soil_number_of_depths)
Expand Down
6 changes: 4 additions & 2 deletions R/benchmark.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ run_plant_benchmarks <- function(strategy_types = list(FF16 = FF16_Strategy,
}

message("Running benchmarks via `run_plant_benchmarks`")
bench::press(strategy = names(strategy_types),
strategy <- names(strategy_types)
bench::press(strategy = strategy,
{
bench::mark(
check = FALSE,
Expand Down Expand Up @@ -58,7 +59,8 @@ run_resource_consumption_benchmarks <- function(its = 10) {
}

message("Running resource consumption benchmarks`")
bench::press(soil_layers = c(1, 10, 50, 100),
soil_layers <- c(1, 10, 50, 100)
bench::press(soil_layers = soil_layers,
{
bench::mark(
check = FALSE,
Expand Down
57 changes: 36 additions & 21 deletions R/ff16.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
##' Create a FF16 Plant or Node
##' @title Create a FF16 Plant or Node
##' Create a FF16 Individual
##' @title Create a FF16 Individual
##' @param s A \code{\link{FF16_Strategy}} object
##' @export
##' @rdname FF16
##' @rdname FF16_individual
##' @examples
##' pl <- FF16_Individual()
##' pl$height
FF16_Individual <- function(s=FF16_Strategy()) {
Individual("FF16", "FF16_Env")(s)
}

##' @title Setup an a model system with default or specified parameters
##'
##' @description Setup an a model system with default or specified parameters.
##' This function enables you initialize a model system. Use the model name to start different models.
##' @param ... Arguments to be passed to the model constructor. These include
##'
##' *`patch_area`: Area of idnividfual patch. Only relevant for stochastic model. Default is 1.0m2.
##' *`max_patch_lifetime`: The maximum time in years we want to simulate
##' *`strategies`: A list of stratgies to simulate. The default is an empty list.
##' *`strategy_default`: Values for the default startegy. The default values are those specified in the C++ code for the model.
##' *`node_schedule_times_default`: Default vector of times at which to introduce nodes. The default is chosen to have close spacing at the start of the simulation.
##' *`node_schedule_times`: A list with each element containing the vector of times we want to introduce nodes for each strategy. The default is an empty list.
##' *`ode_times`: A vector of patch ages we want the ode solver to stop at
##' @export
##' @rdname FF16
FF16_Parameters <- function() {
Parameters("FF16","FF16_Env")()
##' @rdname FF16_Parameters
##' @examples
##' p1 <- FF16_Parameters()
##' p2 <- FF16_Parameters(max_patch_lifetime = 10.0, patch_area = 1.0, strategies = list(FF16_Strategy()), strategy_default = FF16_Strategy(), node_schedule_times_default = node_schedule_times_default(10.0), node_schedule_times = list(node_schedule_times_default(10.0)), ode_times = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
FF16_Parameters <- function(...) {
Parameters("FF16","FF16_Env")(...)
}


## Helper to create FF16_environment object. Useful for running individuals
##' @title create FF16_environment object
##' @param light_availability_spline_tol
##'
##' @param light_availability_spline_nbase
##' @param light_availability_spline_max_depth
##' @param light_availability_spline_rescale_usually
##'
## Helper functions to create an XXX_Environment object. Useful for running individuals
##' @title create a model Environment object
##' @param light_availability_spline_tol Error tolerance of adpative spline method. Deafult is 1e-4.
##' @param light_availability_spline_nbase Parameter used in adaptive spline method. Default is 17.
##' @param light_availability_spline_max_depth Parameter used in adaptive spline method. Default is 16.
##' @inheritParams FF16_Environment
##' @export
##' @rdname FF16_make_environment
FF16_make_environment <- function(light_availability_spline_tol = 1e-4,
Expand All @@ -44,15 +57,16 @@ FF16_make_environment <- function(light_availability_spline_tol = 1e-4,
return(e)
}

##' Construct a fixed environment for FF16 strategy
##' Construct a fixed environment for a model
##'
##' @param e Value of environment (deafult = 1.0)
##' @param height_max = 150.0 maximum possible height in environment
##' @rdname FF16_Environment
##' @param height_max maximum possible height in environment
##' @param ... Additional parameters to be passed to \code{XXXX_make_environment}, where XXXX referes to model name.
##' @rdname FF16_fixed_environment
##'
##' @export
FF16_fixed_environment <- function(e=1.0, height_max = 150.0) {
env <- FF16_make_environment()
FF16_fixed_environment <- function(e=1.0, height_max = 150.0, ...) {
env <- FF16_make_environment(...)
env$set_fixed_environment(e, height_max)
env
}
Expand Down Expand Up @@ -165,7 +179,7 @@ FF16_generate_stand_report <- function(results,
##' @param latitude degrees from equator (0-90), used in solar model [deg]
##' @importFrom stats coef nls
##' @export
##' @rdname FF16_hyperpar
##' @rdname make_FF16_hyperpar
make_FF16_hyperpar <- function(
lma_0=0.1978791,
B_kl1=0.4565855,
Expand Down Expand Up @@ -349,5 +363,6 @@ make_FF16_hyperpar <- function(
##' @param s A strategy object
##' @param filter A flag indicating whether to filter columns. If TRUE, any numbers
##' that are within eps of the default strategy are not replaced.
##' @rdname FF16_hyperpar
##' @export
FF16_hyperpar <- make_FF16_hyperpar()
51 changes: 7 additions & 44 deletions R/ff16r.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
##' @title Create a FF16r Plant or Node
##' @param s A \code{\link{FF16r_Strategy}} object
##' @export
##' @rdname FF16r
##' @rdname FF16r_Individual
##' @examples
##' pl <- FF16r_Individual()
##' pl$height
Expand All @@ -13,50 +13,17 @@ FF16r_Individual <- function(s=FF16r_Strategy()) {
}

##' @export
##' @rdname FF16r
##' @rdname FF16_Parameters
FF16r_Parameters <- function() {
Parameters("FF16r","FF16_Env")()
}

## Helper:
##' @export
##' @rdname FF16_Environment
##' @param light_availability_spline_rescale_usually turns on environment rescaling (default = TRUE)
FF16r_make_environment <- function(light_availability_spline_rescale_usually = TRUE) {

FF16_make_environment(light_availability_spline_rescale_usually)
}


##' This makes a pretend light environment over the plant height,
##' slightly concave up, whatever.
##' @title Create a test environment for FF16r startegy
##' @param height top height of environment object
##' @param n number of points
##' @param light_env function for light environment in test object
##' @param n_strategies number of strategies for test environment
##' @rdname FF16r_test_environment
##' @examples
##' environment <- plant:::FF16r_test_environment(10)
FF16r_test_environment <- function(height, n=101, light_env=NULL,
n_strategies=1) {
hh <- seq(0, height, length.out=n)
if (is.null(light_env)) {
light_env <- function(x) {
exp(x/(height*2)) - 1 + (1 - (exp(.5) - 1))/2
}
}
ee <- light_env(hh)
interpolator <- Interpolator()
interpolator$init(hh, ee)

ret <- FF16r_make_environment()
ret$light_availability$spline <- interpolator
attr(ret, "light_env") <- light_env
ret
}

##' @rdname FF16_make_environment
FF16r_make_environment <- FF16_make_environment

##' @rdname FF16_test_environment
FF16r_test_environment <- FF16_test_environment

##' Hyperparameters for FF16r physiological model
##' @title Hyperparameters for FF16r physiological model
Expand All @@ -82,7 +49,6 @@ FF16r_test_environment <- function(height, n=101, light_env=NULL,
##' @param latitude degrees from equator (0-90), used in solar model [deg]
##' @importFrom stats coef nls
##' @export
##' @rdname FF16r_hyperpar
make_FF16r_hyperpar <- function(
lma_0=0.1978791,
B_kl1=0.4565855,
Expand Down Expand Up @@ -256,9 +222,6 @@ make_FF16r_hyperpar <- function(

##' Hyperparameter function for FF16r physiological model
##' @title Hyperparameter function for FF16r physiological model
##' @param m A matrix of trait values, as returned by \code{trait_matrix}
##' @param s A strategy object
##' @param filter A flag indicating whether to filter columns. If TRUE, any numbers
##' that are within eps of the default strategy are not replaced.
##' @inheritParams FF16_hyperpar
##' @export
FF16r_hyperpar <- make_FF16r_hyperpar()
17 changes: 5 additions & 12 deletions R/ff16w.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ FF16w_Parameters <- function() {
}


## Helper:
##' @export
##' @rdname FF16_Environment
##' @inheritParams FF16_Environment
##' @param soil_number_of_depths the number of soil layers
##' @param soil_initial_state the initial state of the soil layers
##' @param rainfall constant function value for rainfall driver, y = rainfall
##' @rdname FF16_make_environment
FF16w_make_environment <- function(light_availability_spline_tol = 1e-4,
light_availability_spline_nbase = 17,
light_availability_spline_max_depth = 16,
Expand Down Expand Up @@ -70,7 +71,7 @@ FF16w_make_environment <- function(light_availability_spline_tol = 1e-4,
##'
##' @param e Value of environment (deafult = 1.0)
##' @param height_max = 150.0 maximum possible height in environment
##' @rdname FF16_Environment
##' @rdname FF16_fixed_environment
##'
##' @export
FF16w_fixed_environment <- function(e=1.0, height_max = 150.0) {
Expand All @@ -79,15 +80,7 @@ FF16w_fixed_environment <- function(e=1.0, height_max = 150.0) {
env
}


##' This makes a pretend light environment over the plant height,
##' slightly concave up, whatever.
##' @title Create a test environment for FF16w startegy
##' @param height top height of environment object
##' @param n number of points
##' @param light_env function for light environment in test object
##' @param n_strategies number of strategies for test environment
##' @rdname FF16w_test_environment
##' @rdname FF16_test_environment
##' @examples
##' environment <- plant:::FF16w_test_environment(10)
FF16w_test_environment <- function(height,
Expand Down
28 changes: 15 additions & 13 deletions R/individual.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,17 @@ resource_compensation_point.Plant <- function(p, ...) {
#' The function `optimise_individual_rate_at_height_by_trait` and `optimise_individual_rate_at_size_by_trait` solve for the maximum of
#' some rate (e.g. growth rate) at a specified height within
#' the interval of the bounds of a given trait
#' @param type
#' @param bounds
#' @param log_scale
#' @param tol
#' @param size
#' @param size_name
#' @param rate
#' @param params
#' @param env
#' @param hyperpars
#'
#' @param type The type of model to use (e.g. "FF16"). Defaults to "FF16"
#' @param bounds A vector giving the lower and upper bounds of the trait
#' @param log_scale Should the trait be optimised on a log scale? Defaults to TRUE
#' @param tol The tolerance for the optimisation
#' @param size The size of the individual to optimise the rate at
#' @param size_name The name of the size variable specified by \code{size}
#' @param rate The name of the rate to optimise. Defaults to \code{size_name}
#' @param params The parameters of the model
#' @param env The environment of the model
#' @param hyperpars The hyperparameter function of the model
#' @param set_state_directly If TRUE, set the state directly to the size, otherwise grows the plant to that size. Defaults to FALSE
#' @export
#' @rdname optimise_individual_rate_at_size_by_trait
#' @author Isaac Towers, Daniel Falster and Andrew O'Reilly-Nugent
Expand Down Expand Up @@ -332,6 +332,8 @@ optimise_individual_rate_at_size_by_trait <- function(
return(ret)
}

##' @param height Heigh at which grow is optimsied. Defaults to 1
##' @param ... Additional parameters passed to \code{optimise_individual_rate_at_size_by_trait}
#' @export
#' @rdname optimise_individual_rate_at_size_by_trait
optimise_individual_rate_at_height_by_trait <- function(..., height = 1) {
Expand All @@ -350,13 +352,13 @@ solve_max_worker <- function(bounds, f, tol = 1e-3, outcome) {
## NA/Inf replaced by maximum positive value
##
## which is probably the desired behaviour here.
out <- suppressWarnings(optimise(f, interval = bounds, maximum = TRUE, tol = tol))
out <- suppressWarnings(stats::optimise(f, interval = bounds, maximum = TRUE, tol = tol))
# browser()
ret <- out$maximum
attr(ret, outcome) <- out$objective
} else {
## This is not very well tested, and the tolerance is not useful:
out <- optim(rowMeans(bounds), f,
out <- stats::optim(rowMeans(bounds), f,
method = "L-BFGS-B",
lower = bounds[, "lower"], upper = bounds[, "upper"],
control = list(fnscale = -1, factr = 1e10)
Expand Down
Loading

0 comments on commit 1b810de

Please sign in to comment.