Learn R Programming

febr (version 1.9.9)

febr2sse: Conversion between FEBR and SmartSolos Expert (SSE) soil profile data formats

Description

Export FEBR soil profile data to the JSON file format required by the SmartSolos Expert API.

Usage

febr2sse(profiles, horizons, file, ...)

Arguments

profiles

Data frame with soil profile data, i.e. observation locations.

horizons

Data frame with soil horizon data, i.e. sampling layers.

file

(optional) Character string naming the JSON file to be written to disk.

...

(optional) Arguments passed to base::writeLines().

Value

An object of class character containing a unicode JSON string.

References

Jeroen Ooms (2014). The jsonlite Package: A Practical and Consistent Mapping Between JSON Data and R Objects. arXiv:1403.2805 [stat.CO] URL https://arxiv.org/abs/1403.2805.

Examples

Run this code
# NOT RUN {
# Toy example
pro <- data.frame(
  evento_id_febr = "Perfil-1",
  taxon_sibcs_1999 = "Argissolo",
  stringsAsFactors = FALSE
)
hor <- data.frame(
  evento_id_febr = rep("Perfil-1", 3),
  camada_id = c("Ap", "B1", "B2"),
  profund_sup = c(0, 16, 32),
  profund_inf = c(16, 32, 50),
  cor_matriz_umido_munsell = rep("5YR 3/3", 3),
  cor_matriz_seco_munsell = rep("5YR 3/3", 3),
  estrutura_tipo = rep("blocos subangulares", 3),
  estrutura_grau = rep("moderada", 3),
  estrutura_cdiam = rep("m<U+00E9>dia", 3),
  consistencia_umido = rep("fri<U+00E1>vel", 3),
  consistencia_seco = rep("duro", 3),
  plasticidade = rep("pl<U+00E1>stico", 3),
  pegajosidade = rep("pegajoso", 3),
  stringsAsFactors = FALSE
)
febr2sse(pro, hor, tempfile(fileext = ".json"))

# Real example
if (interactive()) {
profiles <- observation(
  data.set = "ctb0025", variable = c("taxon_sibcs", "relevo_drenagem"),
  standardization = list(units = TRUE, round = TRUE))
idx <- profiles$evento_id_febr[1]
profiles <- profiles[profiles$evento_id_febr %in% idx, ]
horizons <- layer(
  data.set = "ctb0025", variable = "all",
  standardization =
    list(plus.sign = "remove", lessthan.sign = "remove",
         transition = "smooth", units = TRUE, round = TRUE))
horizons <- horizons[horizons$evento_id_febr %in% idx, ]
horizons[, 9:48] <- lapply(horizons[, 9:48], as.numeric)
horizons <- cbind(
  horizons,
  morphology(x = horizons$morfologia_descricao, variable = "color"),
  morphology(x = horizons$morfologia_descricao, variable = "structure"),
  morphology(x = horizons$morfologia_descricao, variable = "consistence"),
  stringsAsFactors = FALSE)
file <- ifelse(
  dir.exists("tmp"),
  paste0("tmp/febr2smartsolos-", idx, ".json"),
  paste0(tempdir(), "/febr2smartsolos-", idx, ".json"))
febr2sse(profiles, horizons, file)
}
# }

Run the code above in your browser using DataLab