hm_melt: Melt many objects into an 'hydromet_compact' class object

Description Usage Arguments Value Functions Note Examples

Description

This method allows you merge several tables (inside hydromet_station and/or hydromet_compact class objects) into a single one and set them into the compact slot (hydromet_compact class object).

Usage

1
2
3
4
hm_melt(obj, melt, slot_name, col_name, out_name = NULL)

## S4 method for signature 'hydromet_compact'
hm_melt(obj, melt, slot_name, col_name, out_name = NULL)

Arguments

obj

a valid hydromet_compact class object.

melt

string vector containing the hydromet_xxx class objects names (as you have in the Global Environment) that you want for melting.

slot_name

list (one element per melt vector name) with the slot(s) to extract per every hydromet_xxx class object (as string vectors).

col_name

string vector with the name of the variables to keep. You must comply the following name convention 'melt_slot_variable' (e.g.: 'guido_qd_Q(m3/s)' - where guido is your object name, qd is the slot with daily mean river discharge and Q(m3/s) is the required column name inside that slot). Another option is to set this argument just with the string 'all' and the method will preserve all the slot(s) columns. Other minimal option is to choose the string 'last': in this case you will get only the last column of each slot(s).

out_name

optional. String vector with the output names of the final table. If you use the default value (NULL) the method will add the object and slot name (provided in melt and slot_name argument) at the beginning of every column (e.g.: 'guido_qd_q(m3/s)').

Value

An hydromet_compact class object with a data frame inside the compact slot with all variables that you provided in col_name.

Functions

Note

Remember that all the chosen variables should have the same temporal resolution. The method itself will not warn you about bad entries.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# lets say that we want to put together snow water equivalent from Toscas (dgi)
# and daily streamflow discharge from Guido (snih)

# path to all example files
path <- system.file('extdata', package = 'hydrotoolbox')

# on the first place we build the stations
# dgi file
toscas <-
hm_create() %>%
  hm_build(bureau = 'dgi', path = path,
           file_name = 'dgi_toscas.xlsx',
           slot_name = c('swe', 'tmax',
           'tmin', 'tmean', 'rh', 'patm'),
           by = 'day',
           out_name = c('swe', 'tmax',
           'tmin', 'tmean', 'rh', 'patm') )

# snih file
guido <-
hm_create() %>%
  hm_build(bureau = 'snih', path = path,
           file_name = c('snih_hq_guido.xlsx',
           'snih_qd_guido.xlsx'),
           slot_name = c('hq', 'qd'),
           by = c('none', 'day') )

# now we melt the requiered data
hm_create(class_name = 'compact') %>%
     hm_melt(melt = c('toscas', 'guido'),
             slot_name = list(toscas = 'swe', guido = 'qd'),
             col_name = 'all',
             out_name = c('swe(mm)', 'qd(m3/s)')
             ) %>%
       hm_plot(slot_name = 'compact',
               col_name = list( c('swe(mm)', 'qd(m3/s)') ),
               interactive = TRUE,
               line_color = c('dodgerblue', 'red'),
               y_lab = c('q(m3/s)', 'swe(mm)'),
               dual_yaxis = c('right', 'left')
                )

hydrotoolbox documentation built on July 9, 2021, 1:06 a.m.