Imports data from a user-supplied file, and converts it to a Daily data frame, appropriate for WRTDS calculations. The file can use most any separators as a delimiter. The default is comma separated.
Usage
readUserDaily(filePath, fileName, hasHeader = TRUE, separator = ",",
qUnit = 1, format = "%m/%d/%Y", verbose = TRUE, adjust = TRUE,
fill = FALSE, maxgap = 21, fill_type = "interpolation")Arguments
- filePath
character specifying the path to the file. If it is in the working directory, use ".".
- fileName
character name of file to open
- hasHeader
logical true if the first row of data is the column headers
- separator
character character that separates data cells. The default is "," for a csv file. Tab delimited would be "\t".
- qUnit
number 1 is cubic feet per second, 2 is cubic meters per second, 3 is 10^3 cubic feet per second, and 4 is 10^3 cubic meters per second. The default is 1.
- format
character indicating the format of the date (which should be in the first column). Default is "%m\/%d/%Y". See
?strptimefor options. The code will initially look for R's standard YYYY-MM-DD, and check this format as a backup.- verbose
logical specifying whether or not to display progress message
- adjust
logical specifying whether or not to add a constant to zero values to allow log transformation. Defaults to TRUE.
- fill
logical specifying whether to fill NA values by linear interpolation. Defaults to FALSE.
- maxgap
Maximum number of NA days allowed for interpolating gaps. Default is 21. Only used if fill is set to TRUE.
- fill_type
character to define what process to fill missing data. Options are "interpolation", "spline", or "tsSmooth". "interpolation" is linear interpolation from the `zoo::na.approx`. "spline" is a spline fit using `zoo::na.spline`. "tsSmooth" uses `stats::tsSmooth` which is fixed-interval smoothing on time series. "tsStruct" uses a structural time series models. "log_interp" is linear interpolation in the log space.
Value
A data frame 'Daily' with the following columns:
| Name | Type | Description |
| Date | Date | Date |
| Q | numeric | Discharge in m^3/s |
| Julian | integer | Number of days since Jan. 1, 1850 |
| Month | integer | Month of the year [1-12] |
| Day | integer | Day of the year [1-366] |
| DecYear | numeric | Decimal year |
| MonthSeq | integer | Number of months since January 1, 1850 |
| Qualifier | character | Qualifying code |
| i | integer | Index of days, starting with 1 |
| LogQ | numeric | Natural logarithm of Q |
| Q7 | numeric | 7 day running average of Q |
| Q30 | numeric | 30 day running average of Q |
Details
The first column is expected to be dates, the second column is expected to be discharge values. If the date format is not automatically detected, the format can be specified using the "format" argument.
Examples
filePath <- system.file("extdata", package="EGRET")
fileName <- "ChoptankRiverFlow.txt"
Daily <- readUserDaily(filePath,fileName,separator="\t")
#> The input discharge are assumed to be in cubic feet per second, if they are in cubic meters per second, then the call to readUserDaily should specify qUnit=2
