reformat_snowprofile: Reformat a malformatted snowprofile object

Description Usage Arguments Examples

View source: R/snowprofile.R

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## 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 July 25, 2020, 5:06 p.m.