Adds community observation records to a VegX object from a data table where rows are plot observations.

addCommunityObservations(
  target,
  x,
  mapping,
  methods = list(),
  date.format = "%Y-%m-%d",
  missing.values = c(NA, ""),
  verbose = TRUE
)

Arguments

target

The initial object of class VegX to be modified

x

A data frame where each row corresponds to one plot observation. Columns can be varied.

mapping

A list with element names 'plotName', 'obsStartDate', used to specify the mapping of data columns (specified using strings for column names) onto these variables. Additional optional mappings are: 'subPlotName'.

methods

A named list of objects of class VegXMethodDefinition with the measurement method for each of the community measurements listed in mapping. List names should be the same as subject measurement variables. Alternatively, methods can be specified using strings if predefined methods exist (see predefinedMeasurementMethod).

date.format

A character string specifying the input format of dates (see as.Date).

missing.values

A character vector of values that should be considered as missing observations/measurements.

verbose

A boolean flag to indicate console output of the data integration process.

Value

The modified object of class VegX.

Details

Missing value policy:

  • Missing 'plotName' or 'obsStartDate' values are interpreted as if the previous non-missing value has to be used to define plot observation.

  • Missing 'subPlotName' values are interpreted in that observation refers to the parent plotName.

  • Missing measurements are simply not added to the Veg-X document.

References

Wiser SK, Spencer N, De Caceres M, Kleikamp M, Boyle B & Peet RK (2011). Veg-X - an exchange standard for plot-based vegetation data

Examples

data(Mokihinui)
#> Warning: data set ‘Mokihinui’ not found

# Simulate measurement of basal area
moki_site$BA = pmax(0, rnorm(nrow(moki_site), 10, 5))

# Define mapping
mapping = list(plotName = "Plot", subPlotName = "Subplot",
               obsStartDate = "PlotObsStartDate", basal_area = "BA")


x = addCommunityObservations(newVegX(), moki_site, mapping = mapping,
                        methods = list(basal_area = "Basal area/m2*ha-1"))
#>  Measurement method 'Basal area/m2*ha-1' added for 'basal_area'.
#>  25 plot(s) parsed, 25 new plot(s) added.
#>  25 plot observation(s) parsed, 25 new plot observation(s) added.
#>  25 record(s) parsed, 25 new community observation(s) added.
                        
# Inspect the result
head(showElementTable(x, "communityObservation"))
#>    plotName obsStartDate      comm_1_method comm_1_value
#> 1    LGM08r   2011-02-17 Basal area/m2*ha-1    15.861659
#> 2 LGM08r_1Q   2011-02-17 Basal area/m2*ha-1     5.033530
#> 3 LGM08r_2Q   2011-02-17 Basal area/m2*ha-1    20.714479
#> 4 LGM08r_3Q   2011-02-17 Basal area/m2*ha-1     8.928373
#> 5 LGM08r_4Q   2011-02-17 Basal area/m2*ha-1    10.833506
#> 6    LGM16l   2011-02-15 Basal area/m2*ha-1    11.982943