reformat_snowprofile: Reformat a malformatted snowprofile object

View source: R/snowprofile.R

reformat_snowprofileR Documentation

Reformat a malformatted snowprofile object


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.


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



snowprofile object


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


array of same size than currentFields specifying the new field names


## check the malformatted profile:
this_throws_error <- TRUE
if (!this_throws_error) {
## 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 Aug. 6, 2022, 1:05 a.m.