Learn R Programming

sarp.snowprofile (version 1.3.2)

export.snowprofileCsv: Export or write a snowprofile object to a CSV table

Description

Export or write a snowprofile object to a CSV table

Usage

export.snowprofileCsv(
  profile,
  filename = stop("filename must be provided"),
  sep = ",",
  export.all = "Layers",
  variables = NA
)

Value

Writes csv file to disk, no return value in R

Arguments

profile

snowprofile object

filename

character string, e.g. 'path/to/file.csv'

sep

csv column separator as character string

export.all

one of TRUE, FALSE, 'Layers': export all variables of the snowprofile object to the csv table?

If 'Layers', then all layer variables of the snowprofile will be exported.

variables

A tag-value list of the format, e.g. height = 'height_top', to specify column names of specific variables, to customize column order, and/or to include specific profile meta data if export.all == 'Layers' (e.g. easily include the meta data station_id). Note that the tags of the tag-value list need to correspond to elements of the snowprofile object.

Author

fherla

Details

Note that existing files with the specified filename will be overwritten without warning!

See Also

snowprofileCsv

Examples

Run this code

## export an entire snowprofile object:

export.snowprofileCsv(SPpairs$A_manual, filename = file.path(tempdir(), 'file.csv'),
                      export.all = TRUE)


## export only the layer properties of a snowprofile object,
#  and change the column order with few column names:
#  All layer variables will be exported, but the three ones provided in 'variables'
#  will be the first three columns of the csv table, and their column names will be changed
#  accordingly.

export.snowprofileCsv(SPpairs$A_manual, filename = file.path(tempdir(), 'file.csv'),
                      export.all = 'Layers',
                      variables = list(height = 'height_top', hardness = 'hardness',
                                       gtype = 'gt1'))


## export all layer properties of a snowprofile object plus the station ID:

export.snowprofileCsv(SPpairs$A_manual, filename = file.path(tempdir(), 'file.csv'),
                      export.all = 'Layers', variables = list(station_id = 'station_id'))

## check the content of the exported csv file:
csv_content <- read.csv(file.path(tempdir(), 'file.csv'))
head(csv_content)

## or re-import the csv file as snowprofile object:
csv_snowprofile <- snowprofileCsv(file.path(tempdir(), 'file.csv'))
print(csv_snowprofile)

Run the code above in your browser using DataLab