reformat_snowprofile: Reformat a malformatted snowprofile object

View source: R/snowprofile.R

reformat_snowprofileR Documentation

Reformat a malformatted snowprofile object

Description

Reformat a malformatted snowprofile object. A malformatted object may use field names that deviate from our suggested field names (e.g., grain_type instead of gtype), or it may use data types that are different than what we suggest to use (e.g., ddate as type Date instead of POSIXct). Basically, if your snowprofile object fails the test of validate_snowprofile due to the above reason this function should fix it.

Usage

reformat_snowprofile(profile, currentFields = NULL, targetFields = NULL)

Arguments

profile

snowprofile object

currentFields

array of character strings specifying the current field names that you want to change

targetFields

array of same size than currentFields specifying the new field names

Examples


## check the malformatted profile:
this_throws_error <- TRUE
if (!this_throws_error) {
validate_snowprofile(SPmalformatted[[1]])
}
## i.e., we see that elev and ddate are of wrong data type,
## and a warning that grain_type is an unknown layer property.

## reformat field types, but not the field name:
betterProfile <- reformat_snowprofile(SPmalformatted[[1]])
## i.e., no error is raised anymore, but only the grain_type warning

## so let's reformat also the field names:
optimalProfile <- reformat_snowprofile(SPmalformatted[[1]], "grain_type", "gtype")



## reformat a list of profiles with the same configuration:
SPmalformatted_reformatted <- lapply(SPmalformatted, reformat_snowprofile,
                                     currentFields = "grain_type", targetFields = "gtype")

## the malformatted profile set finally is correctly formatted:
lapply(SPmalformatted_reformatted, validate_snowprofile)



sarp.snowprofile documentation built on March 31, 2023, 5:17 p.m.