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

hm_meltR Documentation

Melt many objects into an hydromet_compact class object

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

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

  • hm_melt(hydromet_compact): plot method for compact class

Note

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

Examples

## Not run: 
# 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')
                )

## End(Not run)



hydrotoolbox documentation built on April 14, 2023, 12:34 a.m.