sanitize_vft | R Documentation |
These functions fix common problems of ViewFullTable and ViewTaxonomy data:
Ensure that each column has the correct type.
Ensure that missing values are represented with NA
s – not with the
literal string "NULL".
sanitize_vft(.data, na = c("", "NA", "NULL"), ...)
sanitize_taxa(.data, na = c("", "NA", "NULL"), ...)
.data |
A dataframe; either a ForestGEO ViewFullTable
( |
na |
Character vector of strings to interpret as missing values. Set this
option to |
... |
Arguments passed to |
A dataframe.
Thanks to Shameema Jafferjee Esufali for motivating this functions.
read_vft()
.
assert_is_installed("fgeo.x")
vft <- fgeo.x::vft_4quad
# Introduce problems to show how to fix them
# Bad column types
vft[] <- lapply(vft, as.character)
# Bad representation of missing values
vft$PlotName <- "NULL"
# "NULL" should be replaced by `NA` and `DBH` should be numeric
str(vft[c("PlotName", "DBH")])
# Fix
vft_sane <- sanitize_vft(vft)
str(vft_sane[c("PlotName", "DBH")])
taxa <- read.csv(fgeo.x::example_path("taxa.csv"))
# E.g. inserting bad column types
taxa[] <- lapply(taxa, as.character)
# E.g. inserting bad representation of missing values
taxa$SubspeciesID <- "NULL"
# "NULL" should be replaced by `NA` and `ViewID` should be integer
str(taxa[c("SubspeciesID", "ViewID")])
# Fix
taxa_sane <- sanitize_taxa(taxa)
str(taxa_sane[c("SubspeciesID", "ViewID")])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.