macroReadBin | R Documentation |
Read bin file from the Soil and MACRO models, including MACRO intermediate-files for metabolite. Adapted by Kristian Persson from an "anonymous" SLU original code . R code vectorisation by Julien Moeys.
macroReadBin(f, ...)
## S3 method for class 'character'
macroReadBin(
f,
header = TRUE,
rmSuffixes = TRUE,
trimLength = integer(),
rmNonAlphaNum = TRUE,
rmSpaces = TRUE,
rmRunID = TRUE,
dateMethod = 1L,
tz = "GMT",
...
)
f |
Vector of character strings or a single |
... |
Additional options passed to specific
methods and to |
header |
Single logical. If |
rmSuffixes |
If |
trimLength |
Single integer value. Number of characters expected for
column names. All characters beyond |
rmNonAlphaNum |
Single logical. If TRUE remove all non alpha-numeric
characters from the column names (and replace them by underscores). See also
the |
rmSpaces |
Single logical. If TRUE remove extra spaces and minus
signs in column names and replace them by underscores _.
Multiple spaces are grouped. Trailing (end) space(s) are
always removed (whatever is the value of |
rmRunID |
Single logical. If TRUE remove the simulation ID at the end
of each column name. |
dateMethod |
Single integer. If 1 uses a new (shorter) method for
converting dates (from the weird bin file format to POSIXct), if 2 uses the
old / slower method implemented for the SOIL model (and MACRO?) and if 0 (or
any other value than 1 or 2) returns the original date in minutes since 2
days before the 1st of January of year 0001 at 00:00. For 1 and 2 the date
returned is POSIXct with time-zone |
tz |
Single character string. "A timezone specification to be used for
the conversion. System-specific (see |
Some global arguments can be set-up and retrieved via muPar
and getMuPar
. Please check the help page of these functions
if you need to tune macroReadBin
.
Returns a data.frame
with the content of the bin file.
If length(f) > 1
, then a list
of data.frame
is returned instead. The Date
column in the bin file is
converted from "Julian Date" into POSIXct
date format.
readBin
.
library( "macroutils2" )
# ====== Example 1: MACRO In FOCUS output file ======
# Path to the file to be read
( filenm <- system.file(
"bintest/chat_winCer_GW-D_1kgHa_d298_annual_output.bin",
package = "macroutils2", mustWork = TRUE ) )
# Read the file - Generic method for reading column names
# (result not always 100 percent clean)
tmp1 <- macroReadBin( f = filenm )
# Read the file - Trim the column names to a known length
# and do not perform any further column name cleaning.
# Optimal length depend on the type of bin-file.
tmp2 <- macroReadBin( f = filenm, trimLength = 52L,
rmSuffixes = FALSE, rmNonAlphaNum = FALSE,
rmSpaces = FALSE, rmRunID = FALSE )
# Read the file - No column names cleaning
tmp3 <- macroReadBin( f = filenm, rmSuffixes = FALSE,
rmNonAlphaNum = FALSE, rmSpaces = FALSE,
rmRunID = FALSE )
colnames( tmp1 )
colnames( tmp2 )
colnames( tmp3 )
dim( tmp1 )
dim( tmp2 )
dim( tmp3 )
# Clean-up
rm( filenm, tmp1, tmp2, tmp3 )
# ====== Example 2: MACRO metabolite intermediate-file ======
# Path to the file to be read
( filenm <- system.file(
"bintest/chat_winCer_GW-C_1kgHa_d298_y1926_int-file.bin",
package = "macroutils2", mustWork = TRUE ) )
# Note: this file has been shortened to only 1 year of data
# Read the file
tmp1 <- macroReadBin( f = filenm )
# Using different settings
tmp3 <- macroReadBin( f = filenm, rmNonAlphaNum = FALSE,
rmSpaces = FALSE, rmRunID = FALSE )
colnames( tmp1 ) # Some column names are not fully cleaned
colnames( tmp3 )
dim( tmp1 )
dim( tmp3 )
# Clean-up
rm( filenm, tmp1, tmp3 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.