data-raw/_GenerateData_sal.R

# Generate salinity data
#
# Erik.Leppo@tetratech.com
# 20180321
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Will be hidden in final package
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# 0. Prep####
library(baytrends)
# assume wd is package directory
wd <- file.path(getwd(),"data-raw")

# 1. Generate Data####
# Load data (sal)
load(file.path(wd, "salinity_1984to2016.rdata"))

# Subset DF
# * down select input data set to those stations in baytrends list ----
df <- sal[sal$Station %in% unique(dataCensored$station)
             , c("Station", "Sample_Date", "Layer", "MeasureValue")]

# ** clean up data structure ----
trim <- function (x) gsub("^\\s+|\\s+$", "", x)
df$Station     <- trim(as.character(df$Station))
df$Layer       <- trim(as.character(df$Layer))
df$Sample_Date <- trim(as.character(df$Sample_Date))
df$Sample_Date <- as.POSIXct(strptime(df$Sample_Date, "%m/%d/%Y"))

# rename columns
# modify names to match other files in package
names(df) <- c("station", "date", "layer", "salinity")


##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 2. Save as RDA for use in package####
#
sal <- df
#setwd("..")
devtools::use_data(sal, overwrite = TRUE)
leppott/baytrends033 documentation built on Feb. 17, 2024, 9:27 a.m.