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

addPlotObservations(
  target,
  x,
  mapping,
  missing.values = c(NA, ""),
  date.format = "%Y-%m-%d",
  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 named list whose elements are strings that correspond to column names in x. Names of the list should be:

  • plotName - A string identifying the vegetation plot within the data set (required).

  • subPlotName - A string identifying a subplot of the plot given by plotName (optional).

  • obsStartDate - Plot observation start date (required; see date.format).

  • projectTitle - Title of the project related to the plot observation (optional).

  • obsEndDate - Plot observation end date (optional; see date.format).

  • observationParty - Name of the party that undertook plot observation (optional).

  • plotUniqueIdentifier - A string used to identify the plot uniquely, preferably globally unique (optional).

missing.values

A character vector of values that should be considered as missing data (see details).

date.format

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

verbose

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

Value

The modified object of class VegX.

Details

Named elements in mapping beyond those used by this function will be ignored. Missing value policy:

  • Missing projectTitle, plotName, obsStartDate or obsEndDate 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 data refers to the parent plotName.

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

# Load source data
data(mokihinui)

# Define mapping
mapping = list(projectTitle = "Project", plotName = "Plot", subPlotName = "Subplot",
               obsStartDate = "PlotObsStartDate", obsEndDate = "PlotObsStopDate")

# Create a new Veg-X document with projects, plots and plot observations (no data)
x = addPlotObservations(newVegX(), moki_site, mapping = mapping)
#>  1 project(s) parsed, 1 new project(s) added.
#>  25 plot(s) parsed, 25 new plot(s) added.
#>  25 plot observation(s) parsed, 25 new plot observation(s) added.

# Examine the result
showElementTable(x, "plot")
#>     plotName relatedPlotName plotRelationship
#> 1     LGM08r            <NA>             <NA>
#> 2  LGM08r_1Q          LGM08r          subplot
#> 3  LGM08r_2Q          LGM08r          subplot
#> 4  LGM08r_3Q          LGM08r          subplot
#> 5  LGM08r_4Q          LGM08r          subplot
#> 6     LGM16l            <NA>             <NA>
#> 7  LGM16l_1Q          LGM16l          subplot
#> 8  LGM16l_2Q          LGM16l          subplot
#> 9  LGM16l_3Q          LGM16l          subplot
#> 10 LGM16l_4Q          LGM16l          subplot
#> 11    LGM38h            <NA>             <NA>
#> 12 LGM38h_1Q          LGM38h          subplot
#> 13 LGM38h_2Q          LGM38h          subplot
#> 14 LGM38h_3Q          LGM38h          subplot
#> 15 LGM38h_4Q          LGM38h          subplot
#> 16    LGM45h            <NA>             <NA>
#> 17 LGM45h_2Q          LGM45h          subplot
#> 18 LGM45h_3Q          LGM45h          subplot
#> 19 LGM45h_4Q          LGM45h          subplot
#> 20    LGM43h            <NA>             <NA>
#> 21 LGM43h_1Q          LGM43h          subplot
#> 22 LGM43h_2Q          LGM43h          subplot
#> 23 LGM43h_3Q          LGM43h          subplot
#> 24 LGM43h_4Q          LGM43h          subplot
#> 25 LGM45h_1Q          LGM45h          subplot
showElementTable(x, "plotObservation")
#>     plotName obsStartDate obsEndDate
#> 1     LGM08r   2011-02-17 2011-02-17
#> 2  LGM08r_1Q   2011-02-17 2011-02-17
#> 3  LGM08r_2Q   2011-02-17 2011-02-17
#> 4  LGM08r_3Q   2011-02-17 2011-02-17
#> 5  LGM08r_4Q   2011-02-17 2011-02-17
#> 6     LGM16l   2011-02-15 2011-02-15
#> 7  LGM16l_1Q   2011-02-15 2011-02-15
#> 8  LGM16l_2Q   2011-02-15 2011-02-15
#> 9  LGM16l_3Q   2011-02-15 2011-02-15
#> 10 LGM16l_4Q   2011-02-15 2011-02-15
#> 11    LGM38h   2011-02-20 2011-02-20
#> 12 LGM38h_1Q   2011-02-20 2011-02-20
#> 13 LGM38h_2Q   2011-02-20 2011-02-20
#> 14 LGM38h_3Q   2011-02-20 2011-02-20
#> 15 LGM38h_4Q   2011-02-20 2011-02-20
#> 16 LGM45h_2Q   2011-02-11 2011-02-11
#> 17 LGM45h_3Q   2011-02-11 2011-02-11
#> 18 LGM45h_4Q   2011-02-11 2011-02-11
#> 19    LGM43h   2011-02-13 2011-02-13
#> 20 LGM43h_1Q   2011-02-13 2011-02-13
#> 21 LGM43h_2Q   2011-02-13 2011-02-13
#> 22 LGM43h_3Q   2011-02-13 2011-02-13
#> 23 LGM43h_4Q   2011-02-13 2011-02-13
#> 24    LGM45h   2011-02-11 2011-02-11
#> 25 LGM45h_1Q   2011-02-11 2011-02-11
#>                                   projectTitle
#> 1  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 2  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 3  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 4  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 5  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 6  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 7  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 8  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 9  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 10 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 11 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 12 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 13 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 14 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 15 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 16 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 17 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 18 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 19 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 20 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 21 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 22 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 23 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 24 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 25 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011

# The same but capturing unique identifiers from data source IDs (not used by the Veg-X package)

mapping = list(projectTitle = "Project", plotName = "Plot", subPlotName = "Subplot",
               obsStartDate = "PlotObsStartDate", obsEndDate = "PlotObsStopDate",
               plotUniqueIdentifier = "PlotID", plotObservationUniqueIdentifier = "PlotObsID")
x = addPlotObservations(newVegX(), moki_site, mapping = mapping)
#>  1 project(s) parsed, 1 new project(s) added.
#>  25 plot(s) parsed, 25 new plot(s) added.
#>  25 plot observation(s) parsed, 25 new plot observation(s) added.

showElementTable(x, "plot")
#>     plotName plotUniqueIdentifier relatedPlotName plotRelationship
#> 1     LGM08r               789033            <NA>             <NA>
#> 2  LGM08r_1Q               789034          LGM08r          subplot
#> 3  LGM08r_2Q               789035          LGM08r          subplot
#> 4  LGM08r_3Q               789036          LGM08r          subplot
#> 5  LGM08r_4Q               789037          LGM08r          subplot
#> 6     LGM16l               789073            <NA>             <NA>
#> 7  LGM16l_1Q               789074          LGM16l          subplot
#> 8  LGM16l_2Q               789075          LGM16l          subplot
#> 9  LGM16l_3Q               789076          LGM16l          subplot
#> 10 LGM16l_4Q               789077          LGM16l          subplot
#> 11    LGM38h               789183            <NA>             <NA>
#> 12 LGM38h_1Q               789184          LGM38h          subplot
#> 13 LGM38h_2Q               789185          LGM38h          subplot
#> 14 LGM38h_3Q               789186          LGM38h          subplot
#> 15 LGM38h_4Q               789187          LGM38h          subplot
#> 16    LGM45h               789218            <NA>             <NA>
#> 17 LGM45h_2Q               789220          LGM45h          subplot
#> 18 LGM45h_3Q               789221          LGM45h          subplot
#> 19 LGM45h_4Q               789222          LGM45h          subplot
#> 20    LGM43h               789208            <NA>             <NA>
#> 21 LGM43h_1Q               789209          LGM43h          subplot
#> 22 LGM43h_2Q               789210          LGM43h          subplot
#> 23 LGM43h_3Q               789211          LGM43h          subplot
#> 24 LGM43h_4Q               789212          LGM43h          subplot
#> 25 LGM45h_1Q               789219          LGM45h          subplot
showElementTable(x, "plotObservation")
#>     plotName obsStartDate obsEndDate plotObservationUniqueIdentifier
#> 1     LGM08r   2011-02-17 2011-02-17                         1161630
#> 2  LGM08r_1Q   2011-02-17 2011-02-17                         1161631
#> 3  LGM08r_2Q   2011-02-17 2011-02-17                         1161632
#> 4  LGM08r_3Q   2011-02-17 2011-02-17                         1161633
#> 5  LGM08r_4Q   2011-02-17 2011-02-17                         1161634
#> 6     LGM16l   2011-02-15 2011-02-15                         1161670
#> 7  LGM16l_1Q   2011-02-15 2011-02-15                         1161671
#> 8  LGM16l_2Q   2011-02-15 2011-02-15                         1161672
#> 9  LGM16l_3Q   2011-02-15 2011-02-15                         1161673
#> 10 LGM16l_4Q   2011-02-15 2011-02-15                         1161674
#> 11    LGM38h   2011-02-20 2011-02-20                         1161780
#> 12 LGM38h_1Q   2011-02-20 2011-02-20                         1161781
#> 13 LGM38h_2Q   2011-02-20 2011-02-20                         1161782
#> 14 LGM38h_3Q   2011-02-20 2011-02-20                         1161783
#> 15 LGM38h_4Q   2011-02-20 2011-02-20                         1161784
#> 16 LGM45h_2Q   2011-02-11 2011-02-11                         1161817
#> 17 LGM45h_3Q   2011-02-11 2011-02-11                         1161818
#> 18 LGM45h_4Q   2011-02-11 2011-02-11                         1161819
#> 19    LGM43h   2011-02-13 2011-02-13                         1161805
#> 20 LGM43h_1Q   2011-02-13 2011-02-13                         1161806
#> 21 LGM43h_2Q   2011-02-13 2011-02-13                         1161807
#> 22 LGM43h_3Q   2011-02-13 2011-02-13                         1161808
#> 23 LGM43h_4Q   2011-02-13 2011-02-13                         1161809
#> 24    LGM45h   2011-02-11 2011-02-11                         1161815
#> 25 LGM45h_1Q   2011-02-11 2011-02-11                         1161816
#>                                   projectTitle
#> 1  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 2  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 3  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 4  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 5  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 6  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 7  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 8  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 9  MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 10 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 11 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 12 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 13 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 14 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 15 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 16 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 17 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 18 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 19 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 20 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 21 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 22 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 23 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 24 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011
#> 25 MOKIHINUI HYDRO PROPOSAL - LOWER GORGE 2011