knitr::opts_chunk$set(echo = TRUE)

spGetPlots

Currently, spGetPlots has a healty number of parameters at 46. This document explores ways in which we could cut that number down. First, here is the current state of spGetPlots.

spGetPlots <- function(bnd = NULL, 
                       bnd_dsn = NULL, 
                       bnd.filter = NULL, 
                       states = NULL, 
                       RS = NULL, 
                       xyids = NULL, 
                       xy_datsource = NULL, 
                       xy = NULL, 
                       xy_dsn = NULL, 
                       xy.uniqueid = "PLT_CN", 
                       xvar = NULL, 
                       yvar = NULL, 
                       xy.crs = 4269, 
                       xyjoinid = NULL, 
                       pjoinid = NULL, 
                       clipxy = TRUE, 
                       datsource = "datamart", 
                       data_dsn =NULL, 
                       istree = FALSE, 
                       isseed = FALSE, 
                       plot_layer = "plot", 
                       cond_layer = "cond", 
                       tree_layer = "tree", 
                       seed_layer = "seed", 
                       ppsa_layer = "pop_plot_stratum_assgn", 
                       other_layers = NULL, 
                       puniqueid = "CN", 
                       savePOP = FALSE, 
                       evalid = NULL, 
                       evalCur = FALSE, 
                       evalEndyr = NULL, 
                       evalType = "VOL", 
                       measCur = FALSE, 
                       measEndyr = NULL, 
                       measEndyr.filter = NULL, 
                       invyrs = NULL, 
                       measyrs =NULL, 
                       allyrs = FALSE, 
                       intensity1 = FALSE, 
                       showsteps = FALSE, 
                       savedata = FALSE, 
                       savebnd = FALSE, 
                       savexy = FALSE, 
                       exportsp = FALSE, 
                       savedata_opts = NULL,
                       spXYdat = NULL) {
  NULL
}

There are some nice ways we could bin these parameters. The _layer parameters in particular would be nice to bin into a list. We could do that like this:

layer_filenames <- function(plot_layer = "plot",
                            cond_layer = "cond",
                            tree_layer = "tree",
                            seed_layer = "seed",
                            ppsa_layer = "pop_plot_stratum_assgn",
                            other_layers = NULL) {
  # Check input parameters
  input.params <- names(as.list(match.call()))[-1]
  formallst <- c(names(formals(title_options)))
  if (!all(input.params %in% formallst)) {
    miss <- input.params[!input.params %in% formallst]
    stop("invalid parameter: ", toString(miss))
  }

  # removes input parameters to create l correctly
  rm(input.params, formallst)

  # create list from input parameters
  l <- c(as.list(environment()), list(...))

  # return list
  return(l)
}

spGetPlots <- function(bnd = NULL, 
                       bnd_dsn = NULL, 
                       bnd.filter = NULL, 
                       states = NULL, 
                       RS = NULL, 
                       xyids = NULL, 
                       xy_datsource = NULL, 
                       xy = NULL, 
                       xy_dsn = NULL, 
                       xy.uniqueid = "PLT_CN", 
                       xvar = NULL, 
                       yvar = NULL, 
                       xy.crs = 4269, 
                       xyjoinid = NULL, 
                       pjoinid = NULL, 
                       clipxy = TRUE, 
                       datsource = "datamart", 
                       data_dsn =NULL, 
                       istree = FALSE, 
                       isseed = FALSE, 
                       layer_fns = layer_filenames(),
                       puniqueid = "CN", 
                       savePOP = FALSE, 
                       evalid = NULL, 
                       evalCur = FALSE, 
                       evalEndyr = NULL, 
                       evalType = "VOL", 
                       measCur = FALSE, 
                       measEndyr = NULL, 
                       measEndyr.filter = NULL, 
                       invyrs = NULL, 
                       measyrs =NULL, 
                       allyrs = FALSE, 
                       intensity1 = FALSE, 
                       showsteps = FALSE, 
                       savedata = FALSE, 
                       savebnd = FALSE, 
                       savexy = FALSE, 
                       exportsp = FALSE, 
                       savedata_opts = NULL,
                       spXYdat = NULL) {
  NULL
}

This cuts us down a tad on number of parameters, but really doesn't help that much. However, I think it does make sense to bin those. Outside of those, I think it is a stretch to bin anything else.



USDAForestService/FIESTA documentation built on April 5, 2025, 4:13 a.m.