Skip to content

Commit

Permalink
fixes for new check errors in R >= 4.4.0 (modules edition)
Browse files Browse the repository at this point in the history
  • Loading branch information
infotroph committed Jul 31, 2024
1 parent b4c3f92 commit 131b7be
Show file tree
Hide file tree
Showing 110 changed files with 713 additions and 573 deletions.
2 changes: 1 addition & 1 deletion Makefile.depends
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ $(call depends,modules/data.atmosphere): | .install/base/db .install/base/logger
$(call depends,modules/data.land): | .install/base/db .install/base/logger .install/base/remote .install/base/settings .install/base/utils .install/base/visualization .install/modules/benchmark
$(call depends,modules/data.remote): | .install/base/db .install/base/logger .install/base/remote .install/base/utils
$(call depends,modules/meta.analysis): | .install/base/db .install/base/logger .install/base/settings .install/base/utils
$(call depends,modules/priors): | .install/base/logger .install/base/visualization .install/modules/meta.analysis
$(call depends,modules/priors): | .install/base/logger .install/base/utils .install/base/visualization .install/modules/meta.analysis
$(call depends,modules/rtm): | .install/base/logger .install/base/utils .install/models/ed .install/modules/assim.batch
$(call depends,modules/uncertainty): | .install/base/db .install/base/logger .install/base/settings .install/base/utils .install/modules/emulator .install/modules/priors
1 change: 1 addition & 0 deletions base/utils/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export(ud_convert)
export(unit_is_parseable)
export(units_are_equivalent)
export(vecpaste)
export(zero.bounded.density)
export(zero.truncate)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
2 changes: 2 additions & 0 deletions base/utils/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# PEcAn.utils 1.8.0.9000

## Added
* utility function `zero.bounded.density` is now exported.


# PEcAn.utils 1.8.0
Expand Down
1 change: 1 addition & 0 deletions base/utils/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ get.run.id <- function(run.type, index, trait = NULL, pft.name = NULL, site.id=N
##' @return data frame with back-transformed log density estimate
##' @author \href{https://stats.stackexchange.com/q/6588/2750}{Rob Hyndman}
##' @references M. P. Wand, J. S. Marron and D. Ruppert, 1991. Transformations in Density Estimation. Journal of the American Statistical Association. 86(414):343-353 \url{http://www.jstor.org/stable/2290569}
##' @export
zero.bounded.density <- function(x, bw = "SJ", n = 1001) {
y <- log(x)
g <- stats::density(y, bw = bw, n = n)
Expand Down
4 changes: 4 additions & 0 deletions docker/depends/pecan_package_dependencies.csv
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"dplyr","*","modules/benchmark","Imports",FALSE
"dplyr","*","modules/data.land","Imports",FALSE
"dplyr","*","modules/data.remote","Suggests",FALSE
"dplyr","*","modules/priors","Suggests",FALSE
"dplyr","*","modules/uncertainty","Imports",FALSE
"dplyr",">= 0.8.1","modules/data.atmosphere","Imports",FALSE
"dplyr",">= 1.1.2","base/db","Imports",FALSE
Expand Down Expand Up @@ -124,6 +125,7 @@
"jsonlite","*","modules/data.remote","Suggests",FALSE
"knitr","*","base/visualization","Suggests",FALSE
"knitr","*","modules/data.atmosphere","Suggests",FALSE
"knitr","*","modules/priors","Suggests",FALSE
"knitr",">= 1.42","base/db","Suggests",FALSE
"knitr",">= 1.42","base/qaqc","Suggests",FALSE
"knitr",">= 1.42","modules/allometry","Suggests",FALSE
Expand Down Expand Up @@ -407,6 +409,7 @@
"PEcAn.utils","*","modules/data.land","Imports",TRUE
"PEcAn.utils","*","modules/data.remote","Imports",TRUE
"PEcAn.utils","*","modules/meta.analysis","Imports",TRUE
"PEcAn.utils","*","modules/priors","Imports",TRUE
"PEcAn.utils","*","modules/rtm","Suggests",TRUE
"PEcAn.utils","*","modules/uncertainty","Imports",TRUE
"PEcAn.utils",">= 1.4.8","models/basgra","Imports",TRUE
Expand Down Expand Up @@ -468,6 +471,7 @@
"rjags","*","modules/data.land","Imports",FALSE
"rjags","*","modules/meta.analysis","Imports",FALSE
"rjags","*","modules/photosynthesis","Depends",FALSE
"rjags","*","modules/priors","Suggests",FALSE
"rjson","*","models/dvmdostem","Imports",FALSE
"rlang","*","base/db","Imports",FALSE
"rlang","*","base/qaqc","Imports",FALSE
Expand Down
2 changes: 1 addition & 1 deletion modules/allometry/vignettes/AllomVignette.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "PEcAn.allometry Vignette"
author: "Mike Dietze"
date: "April 23, 2015"
output: html_document
output: html_vignette
vignette: >
%\VignetteIndexEntry{PEcAn.allometry Vignette}
%\VignetteEngine{knitr::rmarkdown}
Expand Down
1 change: 1 addition & 0 deletions modules/data.land/R/IC_BADM_Utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ entries <- entries[-which(ind),]
#' @param long numeric longitude
#' @param siteid site id as a string
#' @param outdir output dir which you want to store the IC netcdf file
#' @param ens ensemble members, passed on to `pool_ic_list2netcdf`
#'
#' @return a dataframe with file, host, mimetype, formatname, startdate, enddate and dbfile.name columns
#' @export
Expand Down
59 changes: 44 additions & 15 deletions modules/data.land/R/InventoryGrowthFusion.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
##' @name InventoryGrowthFusion
##' @title InventoryGrowthFusion
##' @description this code fuses forest inventory data with tree growth data (tree ring or dendrometer band)
##' for the same plots. Code is a rewrite of Clark et al 2007 Ecol Appl into JAGS
##'
##' @param data list of data inputs
##' @param random = whether or not to include random effects
##' @param n.chunk number of MCMC steps to evaluate at a time. Will only return LAST. If restarting, second number in vector is chunk to start from
##' @param n.burn number of steps to automatically discard as burn-in
##' @param save.state whether or not to include inferred DBH in output (can be large). Enter numeric value to save.state periodically (in terms of n.chunk)
##' @param restart final mcmc.list from previous execution. NULL for new run. TRUE to save final state for new run.
##' @note Requires JAGS
##' @return an mcmc.list object
##' @export
InventoryGrowthFusion <- function(data, cov.data=NULL, time_data = NULL, n.iter=5000, n.chunk = n.iter, n.burn = min(n.chunk, 2000), random = NULL, fixed = NULL,time_varying=NULL, burnin_plot = FALSE, save.jags = "IGF.txt", z0 = NULL, save.state=TRUE,restart = NULL) {
#' InventoryGrowthFusion
#'
#' this code fuses forest inventory data with tree growth data (tree ring or
#' dendrometer band) for the same plots. Code is a rewrite of Clark et al 2007
#' Ecol Appl into JAGS
#'
#' @note Requires JAGS
#'
#' @param data list of data inputs
#' @param cov.data covariate data
#' @param time_data required if time_varying is provided
#' @param n.iter total number of iterations across all chunks
#' @param n.chunk number of MCMC steps to evaluate at a time. Will only return
#' LAST. If restarting, second number in vector is chunk to start from
#' @param n.burn number of steps to automatically discard as burn-in
#' @param random whether or not to include random effects
#' @param fixed formula for fixed effects
#' @param time_varying formula for time-varying effects
#' @param burnin_plot logical: display a plot of the burnin steps?
#' @param save.jags logical: Save the generated JAGS script?
#' @param z0 initial conditions for state variable
#' @param save.state whether or not to include inferred DBH in output (can be
#' large). Enter numeric value to save.state periodically (in terms of
#' n.chunk)
#' @param restart final mcmc.list from previous execution. NULL for new run.
#' TRUE to save final state for new run.
#'
#' @return an mcmc.list object
#' @export
InventoryGrowthFusion <- function(
data,
cov.data = NULL,
time_data = NULL,
n.iter = 5000,
n.chunk = n.iter,
n.burn = min(n.chunk, 2000),
random = NULL,
fixed = NULL,
time_varying = NULL,
burnin_plot = FALSE,
save.jags = "IGF.txt",
z0 = NULL,
save.state = TRUE,
restart = NULL) {

# baseline variables to monitor
burnin.variables <- c("tau_add", "tau_dbh", "tau_inc", "mu") # process variability, dbh and tree-ring observation error, intercept
Expand Down
26 changes: 16 additions & 10 deletions modules/data.land/R/Read_Tuscon.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
##' @title Clean_Tucson
##' @name Clean_Tucson
##' @description tree core QAQC
##' @export
#' Clean_Tucson
#'
#' tree core QAQC
#'
#' @param file WinDendro output
#' @export
Clean_Tucson <- function(file) {
lines <- scan(file, character(), sep = "\n")
split <- strsplit(lines, " ")
Expand Down Expand Up @@ -36,12 +38,16 @@ Clean_Tucson <- function(file) {
return(newfile)
} # Clean_Tucson

##' @title Read_Tucson
##' @name Read_Tucson
##' @export
##' @description wrapper around read.tucson that loads a whole directory of tree ring files
##' and calls a 'clean' function that removes redundant records
##' (WinDendro can sometimes create duplicate records when editing)
#' Read_Tucson
#'
#' wrapper around read.tucson that loads a whole directory of tree ring files
#' and calls a 'clean' function that removes redundant records
#' (WinDendro can sometimes create duplicate records when editing)
#'
#' @param folder path to read files from.
#' Will read all files at this path matching "TXT", "rwl", or "rw"
#'
#' @export
Read_Tucson <- function(folder) {

filenames <- dir(folder, pattern = "TXT", full.names = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion modules/data.land/R/dataone_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @param id "The identifier of a package, package metadata or other package member" -- dataone r
#' @param filepath path to where files will be stored
#' @param CNode
#' @param CNode character, passed to `dataone::CNode`
#' @param lazyLoad "A logical value. If TRUE, then only package member system metadata is downloaded and not data. The default is FALSE." -- dataone R
#' @param quiet "A 'logical'. If TRUE (the default) then informational messages will not be printed." -- dataone R
#'
Expand Down
34 changes: 19 additions & 15 deletions modules/data.land/R/extract.stringCode.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
##' @name extract.stringCode
##' @title extract.string.code
##' @export
#' extract.stringCode
#'
#' @param x string to decode
#' @param extractor function to apply
#'
#' @export
extract.stringCode <- function(x, extractor = from.TreeCode) {
return(extractor(x))
} # extract.stringCode

##' @name from.TreeCode
##' @title from.TreeCode
##' @export
#' from.TreeCode
#' @param x string to decode
#' @export
from.TreeCode <- function(x) {
SITE <- substr(x, 1, 1)
PLOT <- substr(x, 2, 2)
Expand All @@ -16,9 +19,9 @@ from.TreeCode <- function(x) {
return(data.frame(SITE, PLOT, SUBPLOT, TAG))
} # from.TreeCode

##' @name to.TreeCode
##' @title to.TreeCode
##' @export
#' to.TreeCode
#' @param SITE,PLOT,SUBPLOT,TAG strings (or coercible to)
#' @export
to.TreeCode <- function(SITE, PLOT, SUBPLOT, TAG = NULL) {
SITE <- as.character(SITE)
PLOT <- as.character(PLOT)
Expand All @@ -31,17 +34,18 @@ to.TreeCode <- function(SITE, PLOT, SUBPLOT, TAG = NULL) {
return(x)
} # to.TreeCode

##' @name from.Tag
##' @title from.Tag
##' @export
#' from.Tag
#' @param x string to decode
#' @export
from.Tag <- function(x) {
miss <- rep(NA, length(x))
return(data.frame(SITE = miss, PLOT = miss, SUBPLOT = miss, TAG = x))
} # from.Tag

##' @name to.Tag
##' @title to.Tag
##' @export
#' to.Tag
#' @param SITE,PLOT,SUBPLOT ignored
#' @param TAG string (or coercible to)
#' @export
to.Tag <- function(SITE, PLOT, SUBPLOT, TAG = NULL) {
SITE <- as.character(SITE)
PLOT <- as.character(PLOT)
Expand Down
46 changes: 39 additions & 7 deletions modules/data.land/R/extract_soil_nc.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,13 @@ extract_soil_gssurgo<-function(outdir, lat, lon, size=1, radius=500, depths=c(0.



#' Extract soil data
#' Extract soil data from the gridpoint closest to a location
#'
#' @param in.file
#' @param outdir
#' @param lat
#' @param lon
#' @param in.file path to netcdf file containing soil data
#' @param outdir directory in which to write netcdf file of extracted data.
#' Output filename will be the same as input filename.
#' @param lat,lon location in decimal degrees.
#' Data will be extracted from the point in `in.file` that is nearest this
#'
#' @return path to netCDF file containing extracted data
#' @export
Expand Down Expand Up @@ -318,9 +319,40 @@ extract_soil_nc <- function(in.file,outdir,lat,lon){

#' Get standard units for a soil variable
#'
#' @param varname
#' Given SSURGO names for soil properties, looks up their standard units.
#' Note that names must match exactly.
#'
#' @return character
#' Supported variables are:
#' * `soil_depth`
#' * `soil_cec`
#' * `fraction_of_clay_in_soil`
#' * `fraction_of_sand_in_soil`
#' * `fraction_of_silt_in_soil`
#' * `fraction_of_gravel_in_soil`
#' * `volume_fraction_of_water_in_soil_at_saturation`
#' * `volume_fraction_of_water_in_soil_at_field_capacity`
#' * `volume_fraction_of_condensed_water_in_dry_soil`
#' * `volume_fraction_of_condensed_water_in_soil_at_wilting_point`
#' * `soilC`
#' * `soil_ph`
#' * `soil_bulk_density`
#' * `soil_type`
#' * `soil_hydraulic_b`
#' * `soil_water_potential_at_saturation`
#' * `soil_hydraulic_conductivity_at_saturation`
#' * `thcond0`
#' * `thcond1`
#' * `thcond2`
#' * `thcond3`
#' * `soil_thermal_conductivity`
#' * `soil_thermal_conductivity_at_saturation`
#' * `soil_thermal_capacity`
#' * `soil_albedo`
#'
#' @param varname character vector. See details
#'
#' @return character matrix with columns `var` and `unit`
#' @md
#' @export
#'
#' @examples
Expand Down
20 changes: 13 additions & 7 deletions modules/data.land/R/fia2ED.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
# http://opensource.ncsa.illinois.edu/license.html
#-------------------------------------------------------------------------------

##' convert x into a table
##'
##' @title fia.to.psscss
##' @param create pss/css files based on data in the fia database
##' @return nothing
##' @export
##' @author Mike Dietze, Rob Kooper, Ryan Kelly
#' Create pss/css files based on data in the fia database
#'
#' @param settings PEcAn settings object
#' @param lat,lon site location in decimal degrees.
#' Defults to values passed in `settings`.
#' @param year defaults to year of start date passed in settings
#' @param gridres grid resolution in degrees
#' @param min.year,max.year limits on years of FIA data to look for
#' @param overwrite logical: regenerate files already in the database?
#'
#' @return modified settings, invisibly
#' @export
#' @author Mike Dietze, Rob Kooper, Ryan Kelly
fia.to.psscss <- function(settings,
lat = as.numeric(settings$run$site$lat),
lon = as.numeric(settings$run$site$lon),
Expand Down
23 changes: 18 additions & 5 deletions modules/data.land/R/load_veg.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
##' load_veg
##'
##' uses `PEcAn.benchmark::load_data()` to get veg data
##' @export
##' @author Istem Fer
#' load_veg
#'
#' uses `PEcAn.benchmark::load_data()` to get veg data
#'
#' @param new_site list passed to `load_data`
#' @param start_date,end_date date range to look up
#' @param source_id input id to look up in DB
#' @param source name of data source (used in file naming)
#' @param icmeta metadata for initial conditions
#' @param format_name file format to look for
#' @param machine_host hostname of machine where the data lives
#' @param dbparms parameters to use when opening connection to database
#' @param outfolder path to write results
#' @param overwrite Logical: replace existing files? NOTE: Currently ignored!
#' @param ... Additional arguments, currently ignored
#'
#' @export
#' @author Istem Fer
load_veg <- function(new_site, start_date, end_date,
source_id, source, icmeta = NULL, format_name = NULL,
machine_host, dbparms, outfolder, overwrite = FALSE, ...){
Expand Down
10 changes: 8 additions & 2 deletions modules/data.land/R/matchInventoryRings.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
##' @name matchInventoryRings
##' @title matchInventoryRings
#' matchInventoryRings
#'
#' @param trees,rings codes from which to extract IDs
#' @param extractor function to call, specified without its initial `to.`
#' e.g. "TreeCode" calls `to.TreeCode`
#' @param nyears number of years to extract
#' @param coredOnly logical: Only include trees with data from 2000?
#'
##' @export
matchInventoryRings <- function(trees, rings, extractor = "TreeCode", nyears = 30, coredOnly = TRUE) {

Expand Down
1 change: 1 addition & 0 deletions modules/data.land/R/match_species_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#' @param format_name Species code format name (see details)
#' @param bety BETY connection object
#' @param translation_table Data frame with custom translation table (see details).
#' @param ... additional arguments, currently ignored
#' @return \code{data.frame} containing the following columns:
#' \describe{
#' \item{\code{input_code}}{Character provided as input}
Expand Down
3 changes: 2 additions & 1 deletion modules/data.land/R/plot2AGB.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
##'
##' @param combined data frame merging plot inventory and tree ring data
##' @param out MCMC samples for diameter (sample x tree)
##' @param outfolder output folder for graphs & data
##' @param outfolder output folder for graphs & data
##' @param allom.stats Allometry statistics computed by `AllomAve`
##' @param unit.conv area conversion from sum(kg/tree) to kg/area
##'
##' @author Mike Dietze \email{dietze@@bu.edu}
Expand Down
Loading

0 comments on commit 131b7be

Please sign in to comment.