Insert Format and Format-Variable Records

insert.format.vars(con, format_name, mimetype_id, notes = NULL,
  header = TRUE, skip = 0, formats_variables = NULL,
  suppress = TRUE)

Arguments

con

SQL connection to BETYdb

format_name

The name of the format. Type: character string.

mimetype_id

The id associated with the mimetype of the format. Type: integer.

notes

Additional description of the format: character string.

header

Boolean that indicates the presence of a header in the format. Defaults to "TRUE".

skip

Integer that indicates the number of lines to skip in the header. Defaults to 0.

formats_variables

A 'tibble' consisting of entries that correspond to columns in the formats-variables table. See Details for further information.

suppress

Boolean that suppresses or allows a test for an existing variable id. This test is inconvenient in applications where the variable_ids are already known.

Value

format_id

Details

The formats_variables argument must be a 'tibble' and be structured in a specific format so that the SQL query functions properly. All arguments should be passed as vectors so that each entry will correspond with a specific row. All empty values should be specified as NA.

variable_id

(Required) Vector of integers.

name

(Optional) Vector of character strings. The variable name in the imported data need only be specified if it differs from the BETY variable name.

unit

(Optional) Vector of type character string. Should be in a format parseable by the udunits library and need only be secified if the units of the data in the file differ from the BETY standard.

storage_type

(Optional) Vector of character strings. Storage type need only be specified if the variable is stored in a format other than would be expected (e.g. if numeric values are stored as quoted character strings). Additionally, storage_type stores POSIX codes that are used to store any time variables (e.g. a column with a 4-digit year would be %Y). See also [base::strptime]

column_number

Vector of integers that list the column numbers associated with variables in a dataset. Required for text files that lack headers.

Examples

# NOT RUN {
bety <- PEcAn.DB::betyConnect()

formats_variables_tibble <- tibble::tibble(
       variable_id = c(411, 135, 382),
       name = c("NPP", NA, "YEAR"),
       unit = c("g C m-2 yr-1", NA, NA),
       storage_type = c(NA, NA, "%Y"),
       column_number = c(2, NA, 4),
 )
  insert.format.vars(con = bety$con, format_name = "LTER-HFR-103", mimetype_id = 1090, notes = "NPP from Harvard Forest.", header = FALSE, skip = 0, formats_variables = formats_variables_tibble)
# }