validate_snowprofile | R Documentation |
Validator function that checks if snowprofile standards are being met and raises an error if mandatory fields are missing or data types are incorrect. The function raises a warning when unknown field names are encountered.
validate_snowprofile(object, silent = FALSE)
object |
a snowprofile object to be validated |
silent |
remain silent upon error (i.e., don't raise error, but only print it) |
Per default an error is raised when discovered, if silent = TRUE
the error is only printed and the
error message returned (Note: a warning is never returned but only printed!).
If the function is applied to multiple objects, the function returns NULL
for each object if no error
is encountered (see examples below).
reformat_snowprofile
## Validate individual snowprofile and raise an error
## in case of a malformatted profile:
## (1) no error
validate_snowprofile(SPgroup[[1]])
## (2) malformatted profile --> error
this_throws_error <- TRUE
if (!this_throws_error) {
validate_snowprofile(SPmalformatted[[1]])
}
## Validate a list of snowprofiles and raise an error
## when the first error is encountered:
## (i.e., stop subsequent execution)
## (1) no error
lapply(SPgroup, validate_snowprofile)
## (2) malformatted profile --> error
if (!this_throws_error) {
lapply(SPmalformatted, validate_snowprofile)
}
## Validate a list of snowprofiles and continue execution,
## so that you get a comprehensive list of errors of all profiles:
if (!this_throws_error) {
errorlist <- lapply(SPmalformatted, validate_snowprofile, silent = TRUE)
errorlist[sapply(errorlist, function(item) !is.null(item))] # print profiles that caused errors
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.