|
1 | 1 | ##' Get trait data from the database for a single PFT |
2 | 2 | ##' |
3 | | -##' @details `pft` should be a list containing at least `name` and `outdir`, and optionally `posteriorid` and `constants`. BEWARE: All existing files in `outir` will be deleted! |
4 | | -##' @param pft list of settings for the pft whose traits to retrieve. See details |
5 | | -##' @param modeltype type of model that is used, this is used to distinguish between different pfts with the same name. |
| 3 | +##' Queries BETYdb for trait observations and prior distributions for a single |
| 4 | +##' plant functional type (PFT). Results are saved to `.RData` and `.csv` files |
| 5 | +##' in the PFT output directory (`pft$outdir`), and also registered in the |
| 6 | +##' database as posterior records when `write = TRUE`. |
| 7 | +##' |
| 8 | +##' @details |
| 9 | +##' `pft` should be a list containing at least `name` and `outdir`, and |
| 10 | +##' optionally `posteriorid` and `constants`. |
| 11 | +##' **BEWARE:** All existing files in `pft$outdir` will be deleted on entry. |
| 12 | +##' |
| 13 | +##' **File-based side effects (saved to `pft$outdir`):** |
| 14 | +##' \describe{ |
| 15 | +##' \item{`trait.data.Rdata`}{Contains a single object `trait.data`: a named |
| 16 | +##' list of data frames, one per trait. Each data frame has columns from |
| 17 | +##' BETYdb's traits/yields views (e.g., `mean`, `stat`, `n`, `site_id`, |
| 18 | +##' `treatment_id`). Names correspond to trait variable names |
| 19 | +##' (e.g., `"SLA"`, `"Vcmax"`).} |
| 20 | +##' \item{`prior.distns.Rdata`}{Contains a single object `prior.distns`: a |
| 21 | +##' data frame with one row per trait and columns `distn`, `parama`, |
| 22 | +##' `paramb`, and `n`. Row names are trait variable names. Traits listed |
| 23 | +##' in `pft$constants` are excluded.} |
| 24 | +##' \item{`trait.data.csv`}{CSV export of `trait.data` (all traits |
| 25 | +##' row-bound).} |
| 26 | +##' \item{`prior.distns.csv`}{CSV export of `prior.distns`.} |
| 27 | +##' \item{`species.csv` or `cultivars.csv`}{PFT membership list used to |
| 28 | +##' detect changes between runs.} |
| 29 | +##' } |
| 30 | +##' |
| 31 | +##' **Downstream contract:** The files `trait.data.Rdata` and |
| 32 | +##' `prior.distns.Rdata` are expected by [run.meta.analysis.pft()], which |
| 33 | +##' loads them from `pft$outdir`. This implicit file-based coupling means |
| 34 | +##' the two functions must agree on directory path and object names. A future |
| 35 | +##' refactoring goal is to pass these objects directly via function arguments |
| 36 | +##' instead. |
| 37 | +##' |
| 38 | +##' @param pft list of settings for the pft whose traits to retrieve. See details. |
| 39 | +##' @param modeltype type of model that is used, this is used to distinguish |
| 40 | +##' between different pfts with the same name. |
6 | 41 | ##' @param dbfiles location where previous results are found |
7 | 42 | ##' @param dbcon database connection |
8 | | -##' @param forceupdate set this to true to force an update, auto will check to see if an update is needed. |
| 43 | +##' @param forceupdate set this to true to force an update, auto will check to |
| 44 | +##' see if an update is needed. |
9 | 45 | ##' @param write (Logical) If `TRUE` updated posteriors will be written to |
10 | | -##' BETYdb. Defaults to FALSE. |
| 46 | +##' BETYdb. Defaults to `FALSE`. |
11 | 47 | ##' @param trait.names list of trait names to retrieve |
12 | | -##' @return updated pft with posteriorid |
| 48 | +##' @return The `pft` input list, updated with `pft$posteriorid` set to the |
| 49 | +##' ID of the (possibly new) posterior record in BETYdb. Note: the function's |
| 50 | +##' primary outputs (`trait.data`, `prior.distns`) are currently communicated |
| 51 | +##' only through files saved in `pft$outdir`, not through the return value. |
13 | 52 | ##' @author David LeBauer, Shawn Serbin, Rob Kooper |
14 | 53 | ##' @export |
15 | 54 | get.trait.data.pft <- |
|
0 commit comments