Skip to contents

Read a dlf file (Daisy log file) or a directory of dlf files

Usage

read_dlf(
  path,
  mode = "auto",
  pattern = ".*\\.dlf",
  col_name = "sim",
  convert_time = TRUE,
  convert_depth = TRUE
)

Arguments

path

Path to dlf file or directory containing dlf files.

mode

One of 'auto', 'file', 'spawn', 'dir. Default is 'auto'. If 'auto' try to guess the mode. If 'file' assume path is a single dlf file. If 'spawn' assume path is a directory containing log directories generated by the daisy spawn program. If 'dir' assume path is a directory tree containing dlf files

pattern

Regex pattern of files to include. Only relevant for modes 'auto', 'spawn', and 'dir'

col_name

Name of column to store directory name in. Only relevant for modes 'auto' and 'spawn'.

convert_time

If TRUE convert daisy time to a timestamp stored under column 'time' in the data slot of each dlf

convert_depth

If TRUE and the file contains depth data, convert it to a nicer depth format with three columns (depth, time, variable). It implies convert_time=TRUE

Value

For mode 'file': An S4 object of class Dlf with three slots: header, units, data. header is list with everything in the dlf file before the data. key: value pairs from the header are stored as named components of the list. units is a data.frame containing the units of the values in data. data is a data.frame containing the logged values

For mode 'spawn': A named list of Dlf objects, where names are names of log types For mode 'dir': A named list of Dlf objects, where names are paths to each file.

See also

read_dlf_file, read_dlf_dir, read_dlf_spawn

Examples

data_dir <- system.file("extdata", package="daisyrVis")
path <- file.path(data_dir, "annual/Annual-FN/HourlyP-Annual-FN-2-2b.dlf")
dlf <- read_dlf(path)
slotNames(dlf)
#> [1] "header" "units"  "data"  
names(dlf@header)
#> [1] "info"     "VERSION"  "LOGFILE"  "RUN"      "COLUMN"   "INTERVAL" "LOG"     
#> [8] "SIMFILE"  "SIM"     
dlf@units$Crop
#> [1] "kg N/ha"
dlf$Crop # equivalent to dlf@data$Crop
#>  [1]   0.0000  27.9559 138.0880  11.4810  24.6333   0.0000  10.8504 133.5410
#>  [9]  34.2416  35.3079   0.0000
dlf[["Crop"]]
#>  [1]   0.0000  27.9559 138.0880  11.4810  24.6333   0.0000  10.8504 133.5410
#>  [9]  34.2416  35.3079   0.0000