Process ECOTOX search results by converting character
to numeric
where relevant
Source: R/process.r
process_ecotox_numerics.Rd
The function
search_ecotox()
returns fields
from the ECOTOX database as is. Many numeric values are stored in the database as
text. It is not uncommon that these text fields cannot be converted directly and need
some sanitising first. process_ecotox_numerics()
takes a data.frame
returned by
search_ecotox()
, locates numeric columns, represented by text, sanitises the text
and converts them to numerics.
Arguments
- x
A
data.frame
obtained withsearch_ecotox()
, for which the numerics need to be processed.- .fns
Function to convert
character
tonumeric
. By defaultas_numeric_ecotox()
is used which also sanitises the input. You can also useas.numeric()
if you don't want the sanitation step. You can also write a custom function.- ...
Arguments passed to
.fns
.- .names
A 'glue' specification used to rename the numeric columns. By default it is
"{.col}"
, which will overwrite existing text columns with numeric columns. You can for instance add a suffix with"{.col}_num"
if you want to rename the resulting numeric columns.
Value
Returns a data.frame
in which the columns containing numeric information
is converted from the character format from the database to actual numerics.
Examples
if (check_ecotox_availability()) {
df <- search_ecotox(
list(
latin_name = list(
terms = c("Skeletonema", "Daphnia"),
method = "contains"
),
chemical_name = list(
terms = "benzene",
method = "exact"
)
), list_ecotox_fields("full"))
df_num <-
process_ecotox_numerics(df, warn = FALSE)
}