From b53b3169864093862873fff009e53bb5b7389906 Mon Sep 17 00:00:00 2001 From: Ben Bond-Lamberty Date: Tue, 10 Feb 2026 19:09:22 -0500 Subject: [PATCH 1/6] Add read_L1 and read_L2 functions --- DESCRIPTION | 3 +- NAMESPACE | 3 ++ R/data.R | 106 +++++++++++++++++++++++++++++++++++++++++++++++++ man/read_L1.Rd | 39 ++++++++++++++++++ man/read_L2.Rd | 39 ++++++++++++++++++ 5 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 R/data.R create mode 100644 man/read_L1.Rd create mode 100644 man/read_L2.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 916c69e..ee9a3cf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,7 +19,8 @@ Imports: fpeek, lubridate, tidyr (>= 1.0), - dplyr (>= 1.0) + dplyr (>= 1.0), + arrow (>= 20.0) Suggests: rdrop2 (>= 0.8), covr, diff --git a/NAMESPACE b/NAMESPACE index b92c55f..c933e5c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,8 @@ export(nearest_neighbor_TMP) export(process_aquatroll_dir) export(process_sapflow_dir) export(process_teros_dir) +export(read_L1) +export(read_L2) export(read_aquatroll200_file) export(read_aquatroll600_file) export(read_datalogger_file) @@ -14,6 +16,7 @@ export(read_teros_file) export(scan_folders) import(dplyr) import(fpeek) +importFrom(arrow,read_parquet) importFrom(dplyr,bind_rows) importFrom(lubridate,ymd_hms) importFrom(readr,col_character) diff --git a/R/data.R b/R/data.R new file mode 100644 index 0000000..8fc7e31 --- /dev/null +++ b/R/data.R @@ -0,0 +1,106 @@ +# data.R + +# These two functions share 95% of their code, but they're short + + +#' Read L1 (Level 1) sensor data files +#' +#' This function reads the COMPASS-FME L1 data files (CSV format) +#' for a single variable, from one or more sites, and returns +#' the compiled data. +#' +#' @param variable Variable name ('research name') to be read, character +#' @param site Optional name of the site(s) of data to read, character +#' @param path Optional path of the L1 dataset, character +#' @param quiet Print diagnostic information? Logical +#' @importFrom dplyr bind_rows +#' @importFrom readr read_csv +#' @returns A \code{\link[tibble]{tibble}} of L1 data. +#' @export +#' @author BBL +#' @note This function only works for L1 v2-0 (July 2025) and higher. +#' @examples +#' \dontrun{ +#' read_L1("gw-tds", site = "TMP") +#' read_L1("gw-tds", c("TMP", "OWC")) # multiple sites +#' read_L1(variable = "gw-tds") # will read all sites' data +#' read_L1(variable = "gw-tds", path = "/path/to/L1/data") +#' } +read_L1 <- function(variable, site = NULL, path = ".", quiet = FALSE) { + + if(length(variable) > 1) { + stop("Only one variable can be read at a time") + } + if(is.null(site)) { + sites <- "[A-Z]*" + } else { + sites <- paste0("(", paste(site, collapse = "|"), ")") + } + # Construct regular expression to identify files + regex <- paste0("^", sites, "_[A-Z]+_.*_", variable, "_L1_.*csv$") + if(!quiet) message(regex) + files <- list.files(path, pattern = regex, recursive = TRUE) + if(!quiet) message("Reading ", length(files), " files") + + # The function works fine reading zero files, but this is + # probably not what the user wants + stopifnot(length(files) > 0) + + x <- lapply(files, function(f) { + if(!quiet) message("\t", f) + read_csv(file.path(path, f), col_types = "ccTccccdcclll") + }) + bind_rows(x) +} + + + +#' Read L2 (Level 2) sensor data files (Parquet format) +#' +#' This function reads the COMPASS-FME L2 data files (Parquet format) +#' for a single variable, from one or more sites, and returns +#' the compiled data. +#' +#' @param variable Variable name ('research name') to be read, character +#' @param site Optional name of the site(s) of data to read, character +#' @param path Optional path of the L2 dataset, character +#' @param quiet Print diagnostic information? Logical +#' @importFrom dplyr bind_rows +#' @importFrom arrow read_parquet +#' @returns A \code{\link[tibble]{tibble}} of L2 data. +#' @export +#' @author BBL +#' @note This function only works for L2 v2-0 (July 2025) and higher. +#' @examples +#' \dontrun{ +#' read_L2("gw-tds", site = "TMP") +#' read_L2("gw-tds", c("TMP", "OWC")) # multiple sites +#' read_L2(variable = "gw-tds") # will read all sites' data +#' read_L2(variable = "gw-tds", path = "/path/to/L2/data") +#' } +read_L2 <- function(variable, site = NULL, path = ".", quiet = FALSE) { + + if(length(variable) > 1) { + stop("Only one variable can be read at a time") + } + if(is.null(site)) { + sites <- "[A-Z]*" + } else { + sites <- paste0("(", paste(site, collapse = "|"), ")") + } + # Construct regular expression to identify files + regex <- paste0("^", sites, "_[A-Z]+_.*_", variable, "_L2_.*parquet$") + if(!quiet) message(regex) + files <- list.files(path, pattern = regex, recursive = TRUE) + if(!quiet) message("Reading ", length(files), " files") + + # The function works fine reading zero files, but this is + # probably not what the user wants + stopifnot(length(files) > 0) + + x <- lapply(files, function(f) { + if(!quiet) message("\t", f) + read_parquet(file.path(path, f)) + }) + bind_rows(x) +} diff --git a/man/read_L1.Rd b/man/read_L1.Rd new file mode 100644 index 0000000..b342dd6 --- /dev/null +++ b/man/read_L1.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\name{read_L1} +\alias{read_L1} +\title{Read L1 (Level 1) sensor data files} +\usage{ +read_L1(variable, site = NULL, path = ".", quiet = FALSE) +} +\arguments{ +\item{variable}{Variable name ('research name') to be read, character} + +\item{site}{Optional name of the site(s) of data to read, character} + +\item{path}{Optional path of the L1 dataset, character} + +\item{quiet}{Print diagnostic information? Logical} +} +\value{ +A \code{\link[tibble]{tibble}} of L1 data. +} +\description{ +This function reads the COMPASS-FME L1 data files (CSV format) +for a single variable, from one or more sites, and returns +the compiled data. +} +\note{ +This function only works for L1 v2-0 (July 2025) and higher. +} +\examples{ +\dontrun{ +read_L1("gw-tds", site = "TMP") +read_L1("gw-tds", c("TMP", "OWC")) # multiple sites +read_L1(variable = "gw-tds") # will read all sites' data +read_L1(variable = "gw-tds", path = "/path/to/L1/data") +} +} +\author{ +BBL +} diff --git a/man/read_L2.Rd b/man/read_L2.Rd new file mode 100644 index 0000000..478b841 --- /dev/null +++ b/man/read_L2.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\name{read_L2} +\alias{read_L2} +\title{Read L2 (Level 2) sensor data files (Parquet format)} +\usage{ +read_L2(variable, site = NULL, path = ".", quiet = FALSE) +} +\arguments{ +\item{variable}{Variable name ('research name') to be read, character} + +\item{site}{Optional name of the site(s) of data to read, character} + +\item{path}{Optional path of the L2 dataset, character} + +\item{quiet}{Print diagnostic information? Logical} +} +\value{ +A \code{\link[tibble]{tibble}} of L2 data. +} +\description{ +This function reads the COMPASS-FME L2 data files (Parquet format) +for a single variable, from one or more sites, and returns +the compiled data. +} +\note{ +This function only works for L2 v2-0 (July 2025) and higher. +} +\examples{ +\dontrun{ +read_L2("gw-tds", site = "TMP") +read_L2("gw-tds", c("TMP", "OWC")) # multiple sites +read_L2(variable = "gw-tds") # will read all sites' data +read_L2(variable = "gw-tds", path = "/path/to/L2/data") +} +} +\author{ +BBL +} From e5a62e59ba801f19b66afaac85d09c23a9422307 Mon Sep 17 00:00:00 2001 From: Ben Bond-Lamberty Date: Tue, 10 Feb 2026 19:36:22 -0500 Subject: [PATCH 2/6] Add test code --- R/data.R | 4 +-- tests/testthat/test-read_Lx.R | 32 ++++++++++++++++++ ...CRC_OW_2024_sonde-fdom-rfu_L2_v2-1.parquet | Bin 0 -> 3491 bytes ...TMP_F_20191120-20191231_gw-tds_L1_v2-1.csv | 8 +++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 tests/testthat/test-read_Lx.R create mode 100644 tests/testthat/test_data/CRC_OW_2024_sonde-fdom-rfu_L2_v2-1.parquet create mode 100644 tests/testthat/test_data/TMP_F_20191120-20191231_gw-tds_L1_v2-1.csv diff --git a/R/data.R b/R/data.R index 8fc7e31..364a969 100644 --- a/R/data.R +++ b/R/data.R @@ -44,7 +44,7 @@ read_L1 <- function(variable, site = NULL, path = ".", quiet = FALSE) { # The function works fine reading zero files, but this is # probably not what the user wants - stopifnot(length(files) > 0) + if(length(files) == 0) warning("No files found") x <- lapply(files, function(f) { if(!quiet) message("\t", f) @@ -96,7 +96,7 @@ read_L2 <- function(variable, site = NULL, path = ".", quiet = FALSE) { # The function works fine reading zero files, but this is # probably not what the user wants - stopifnot(length(files) > 0) + if(length(files) == 0) warning("No files found") x <- lapply(files, function(f) { if(!quiet) message("\t", f) diff --git a/tests/testthat/test-read_Lx.R b/tests/testthat/test-read_Lx.R new file mode 100644 index 0000000..58b148d --- /dev/null +++ b/tests/testthat/test-read_Lx.R @@ -0,0 +1,32 @@ +# read_Lx functions + +test_that("read_L1 works", { + # Handles bad input + expect_error(read_L1(letters[1:2]), regexp = "Only one variable") + + # Works + x <- read_L1(variable = "gw-tds", path = "./test_data", quiet = TRUE) + expect_s3_class(x, "data.frame") + + # Respects quiet flag + expect_no_message(read_L1(variable = "gw-tds", path = "./test_data", quiet = TRUE)) + + # Warns if no files found + expect_warning(read_L1("A", quiet = TRUE), regexp = "No files found") +}) + + +test_that("read_L2 works", { + # Handles bad input + expect_error(read_L2(letters[1:2]), regexp = "Only one variable") + + # Works + x <- read_L2(variable = "sonde-fdom-rfu", path = "./test_data", quiet = TRUE) + expect_s3_class(x, "data.frame") + + # Respects quiet flag + expect_no_message(read_L2(variable = "sonde-fdom-rfu", path = "./test_data", quiet = TRUE)) + + # Warns if no files found + expect_warning(read_L2("A", quiet = TRUE), regexp = "No files found") +}) diff --git a/tests/testthat/test_data/CRC_OW_2024_sonde-fdom-rfu_L2_v2-1.parquet b/tests/testthat/test_data/CRC_OW_2024_sonde-fdom-rfu_L2_v2-1.parquet new file mode 100644 index 0000000000000000000000000000000000000000..f7f69870e63d077f51e9959eeb2b845aa1297524 GIT binary patch literal 3491 zcmb_fU1(fI6rSDee>cfC>W#13a8&x|?*q6!^InaladNdOT0gyb0|u?O#HB=d0hG9{(4a z&;whS=cB)7!1eYg?>jw%%VXa@z?7NapWquN?4FR^hISnag9(fO%e zsQPG|u{dYI1~7b=1P}Ea2@XHRBeiF#N2ompA*cj~g8mJwa7$tpg8V+(WdL_X+90}C zDHn=8i-pQcPjzwq|C;7``9E*`zgw@o*DgyfPr>mnMi-G;@PHB|8k@G}jgTdaV|N4x)`={M zS7S72@J~bAsf5@79b|yRhKU?v*KE4gh1OF$jlvjqw^|y*?m2V|qz$o~PTdlbmt6Fy z02J0mw?1~&j-mJ6Vo+px#0Yk;c+Ku3uNFWZ@~{0wa@F$7#g!}t`TYCsl4I`lT5&&# zg@Baim@ZY;42J_EyovG2(YXYloZcUdeXuvwjUs8WzVUKxt-8KaESnjK*;;omj7JPC z9P!Q-%e6|?;`PKT`Rv;1O1Uw#wOXtdv(^0aLOHu)GV}q6GnFl^7oi}qA799BENOjL ze4$XStP+YrUJuM9y(WCoXx zK0b$yI&R4qD{sgLJw*O;VMS1bg>IrAV>r3~s6v$S$iZ-U5L}}XSUo@^K@`GxlF(7p zne_SIlQSH6Eur3m9}JA}n3*3HNiYdK4f%(`R4<&IkC!s@6KAr~q4i9(rALa_jD2De_E8z5tdXy{{IpWvJ9D; Date: Tue, 10 Feb 2026 19:45:47 -0500 Subject: [PATCH 3/6] Make path required and expand testing --- R/data.R | 8 +++---- man/read_L1.Rd | 6 ++--- man/read_L2.Rd | 6 ++--- tests/testthat/test-read_Lx.R | 22 ++++++++++++++---- ...OWC_OW_2024_sonde-fdom-rfu_L2_v2-1.parquet | Bin 0 -> 3491 bytes ...WC_UP_20191120-20191231_gw-tds_L1_v2-1.csv | 8 +++++++ 6 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 tests/testthat/test_data/OWC_OW_2024_sonde-fdom-rfu_L2_v2-1.parquet create mode 100644 tests/testthat/test_data/OWC_UP_20191120-20191231_gw-tds_L1_v2-1.csv diff --git a/R/data.R b/R/data.R index 364a969..8ec1542 100644 --- a/R/data.R +++ b/R/data.R @@ -10,8 +10,8 @@ #' the compiled data. #' #' @param variable Variable name ('research name') to be read, character +#' @param path Path of the L1 dataset, character #' @param site Optional name of the site(s) of data to read, character -#' @param path Optional path of the L1 dataset, character #' @param quiet Print diagnostic information? Logical #' @importFrom dplyr bind_rows #' @importFrom readr read_csv @@ -26,7 +26,7 @@ #' read_L1(variable = "gw-tds") # will read all sites' data #' read_L1(variable = "gw-tds", path = "/path/to/L1/data") #' } -read_L1 <- function(variable, site = NULL, path = ".", quiet = FALSE) { +read_L1 <- function(variable, path, site = NULL, quiet = FALSE) { if(length(variable) > 1) { stop("Only one variable can be read at a time") @@ -62,8 +62,8 @@ read_L1 <- function(variable, site = NULL, path = ".", quiet = FALSE) { #' the compiled data. #' #' @param variable Variable name ('research name') to be read, character +#' @param path Path of the L2 dataset, character #' @param site Optional name of the site(s) of data to read, character -#' @param path Optional path of the L2 dataset, character #' @param quiet Print diagnostic information? Logical #' @importFrom dplyr bind_rows #' @importFrom arrow read_parquet @@ -78,7 +78,7 @@ read_L1 <- function(variable, site = NULL, path = ".", quiet = FALSE) { #' read_L2(variable = "gw-tds") # will read all sites' data #' read_L2(variable = "gw-tds", path = "/path/to/L2/data") #' } -read_L2 <- function(variable, site = NULL, path = ".", quiet = FALSE) { +read_L2 <- function(variable, path, site = NULL, quiet = FALSE) { if(length(variable) > 1) { stop("Only one variable can be read at a time") diff --git a/man/read_L1.Rd b/man/read_L1.Rd index b342dd6..ca9e578 100644 --- a/man/read_L1.Rd +++ b/man/read_L1.Rd @@ -4,14 +4,14 @@ \alias{read_L1} \title{Read L1 (Level 1) sensor data files} \usage{ -read_L1(variable, site = NULL, path = ".", quiet = FALSE) +read_L1(variable, path, site = NULL, quiet = FALSE) } \arguments{ \item{variable}{Variable name ('research name') to be read, character} -\item{site}{Optional name of the site(s) of data to read, character} +\item{path}{Path of the L1 dataset, character} -\item{path}{Optional path of the L1 dataset, character} +\item{site}{Optional name of the site(s) of data to read, character} \item{quiet}{Print diagnostic information? Logical} } diff --git a/man/read_L2.Rd b/man/read_L2.Rd index 478b841..cca5caf 100644 --- a/man/read_L2.Rd +++ b/man/read_L2.Rd @@ -4,14 +4,14 @@ \alias{read_L2} \title{Read L2 (Level 2) sensor data files (Parquet format)} \usage{ -read_L2(variable, site = NULL, path = ".", quiet = FALSE) +read_L2(variable, path, site = NULL, quiet = FALSE) } \arguments{ \item{variable}{Variable name ('research name') to be read, character} -\item{site}{Optional name of the site(s) of data to read, character} +\item{path}{Path of the L2 dataset, character} -\item{path}{Optional path of the L2 dataset, character} +\item{site}{Optional name of the site(s) of data to read, character} \item{quiet}{Print diagnostic information? Logical} } diff --git a/tests/testthat/test-read_Lx.R b/tests/testthat/test-read_Lx.R index 58b148d..cc4e865 100644 --- a/tests/testthat/test-read_Lx.R +++ b/tests/testthat/test-read_Lx.R @@ -4,15 +4,22 @@ test_that("read_L1 works", { # Handles bad input expect_error(read_L1(letters[1:2]), regexp = "Only one variable") - # Works + # Single site + x <- read_L1(variable = "gw-tds", path = "./test_data", site = "TMP", quiet = TRUE) + expect_s3_class(x, "data.frame") + expect_true(all(x$Site == "TMP")) + + # Multiple sites x <- read_L1(variable = "gw-tds", path = "./test_data", quiet = TRUE) expect_s3_class(x, "data.frame") + expect_true(length(unique(x$Site)) > 1) # Respects quiet flag expect_no_message(read_L1(variable = "gw-tds", path = "./test_data", quiet = TRUE)) # Warns if no files found - expect_warning(read_L1("A", quiet = TRUE), regexp = "No files found") + expect_warning(read_L1("A", path = "./test_data", quiet = TRUE), + regexp = "No files found") }) @@ -20,13 +27,20 @@ test_that("read_L2 works", { # Handles bad input expect_error(read_L2(letters[1:2]), regexp = "Only one variable") - # Works + # Single site + x <- read_L2(variable = "sonde-fdom-rfu", path = "./test_data", site = "OWC", quiet = TRUE) + expect_s3_class(x, "data.frame") + expect_true(all(x$Site == "OWC")) + + # Multiple sites x <- read_L2(variable = "sonde-fdom-rfu", path = "./test_data", quiet = TRUE) expect_s3_class(x, "data.frame") + expect_true(length(unique(x$Site)) > 1) # Respects quiet flag expect_no_message(read_L2(variable = "sonde-fdom-rfu", path = "./test_data", quiet = TRUE)) # Warns if no files found - expect_warning(read_L2("A", quiet = TRUE), regexp = "No files found") + expect_warning(read_L2("A", path = "./test_data", quiet = TRUE), + regexp = "No files found") }) diff --git a/tests/testthat/test_data/OWC_OW_2024_sonde-fdom-rfu_L2_v2-1.parquet b/tests/testthat/test_data/OWC_OW_2024_sonde-fdom-rfu_L2_v2-1.parquet new file mode 100644 index 0000000000000000000000000000000000000000..b00b9ec6433ca3eefa715070610f442828e90723 GIT binary patch literal 3491 zcmb_fU1(fI6rSDee>cfC>z84d?TcoXB3qjL#9IlVs^`(SUV8%5G$edFcYT6MitD4Q9G*;;omj7JPC z9P!Q-%C$<>;`PKTx$N5MO1Uw#wOXhZven$mLOEM98TtUknaUQ|3s4Z)k1u35mbJbs zzL2k0Rtd!*uLxS00{yW zK}-I&`H`^M@*yeCz&0U0U+No=3j@3221g zCp5hT-v+(TLZq6UOZG;Sy|Zc}g-BSaqR!zhs0x?H7fW4DrA8-tpGA-3nAxC*h>xnZ z#Uq+V7cd^`7m5XNGr0BQ+yEIvL_;6z`UKx(U-2;11U@3ALBCgt)VZ3io?9=h_2gDp ld$QGPWwUdmP_4lij?TWrhu}}X3txYB{Seg)zmnkR+23 Date: Tue, 10 Feb 2026 19:47:46 -0500 Subject: [PATCH 4/6] Bump version number to match data release --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ee9a3cf..57ac985 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: compasstools Title: COMPASS Utilities and Tools -Version: 0.2 +Version: 2.1 Authors@R: c( person("Ben", "Bond-Lamberty", email = "bondlamberty@pnnl.gov", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-9525-4633")), From 7e348bc44a5a4f217fecbbcb15181adb9c7ea87e Mon Sep 17 00:00:00 2001 From: Ben Bond-Lamberty Date: Wed, 11 Feb 2026 05:15:51 -0500 Subject: [PATCH 5/6] Renaming --- NAMESPACE | 4 ++-- R/{data.R => read_Lx_variable.R} | 22 ++++++++++----------- man/{read_L1.Rd => read_L1_variable.Rd} | 16 +++++++-------- man/{read_L2.Rd => read_L2_variable.Rd} | 16 +++++++-------- tests/testthat/test-read_Lx.R | 26 ++++++++++++------------- 5 files changed, 42 insertions(+), 42 deletions(-) rename R/{data.R => read_Lx_variable.R} (82%) rename man/{read_L1.Rd => read_L1_variable.Rd} (63%) rename man/{read_L2.Rd => read_L2_variable.Rd} (63%) diff --git a/NAMESPACE b/NAMESPACE index c933e5c..6f3f00b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,8 +5,8 @@ export(nearest_neighbor_TMP) export(process_aquatroll_dir) export(process_sapflow_dir) export(process_teros_dir) -export(read_L1) -export(read_L2) +export(read_L1_variable) +export(read_L2_variable) export(read_aquatroll200_file) export(read_aquatroll600_file) export(read_datalogger_file) diff --git a/R/data.R b/R/read_Lx_variable.R similarity index 82% rename from R/data.R rename to R/read_Lx_variable.R index 8ec1542..fa1c01f 100644 --- a/R/data.R +++ b/R/read_Lx_variable.R @@ -1,4 +1,4 @@ -# data.R +# read_Lx_variable.R # These two functions share 95% of their code, but they're short @@ -21,12 +21,12 @@ #' @note This function only works for L1 v2-0 (July 2025) and higher. #' @examples #' \dontrun{ -#' read_L1("gw-tds", site = "TMP") -#' read_L1("gw-tds", c("TMP", "OWC")) # multiple sites -#' read_L1(variable = "gw-tds") # will read all sites' data -#' read_L1(variable = "gw-tds", path = "/path/to/L1/data") +#' read_L1_variable("gw-tds", site = "TMP") +#' read_L1_variable("gw-tds", c("TMP", "OWC")) # multiple sites +#' read_L1_variable(variable = "gw-tds") # will read all sites' data +#' read_L1_variable(variable = "gw-tds", path = "/path/to/L1/data") #' } -read_L1 <- function(variable, path, site = NULL, quiet = FALSE) { +read_L1_variable <- function(variable, path, site = NULL, quiet = FALSE) { if(length(variable) > 1) { stop("Only one variable can be read at a time") @@ -73,12 +73,12 @@ read_L1 <- function(variable, path, site = NULL, quiet = FALSE) { #' @note This function only works for L2 v2-0 (July 2025) and higher. #' @examples #' \dontrun{ -#' read_L2("gw-tds", site = "TMP") -#' read_L2("gw-tds", c("TMP", "OWC")) # multiple sites -#' read_L2(variable = "gw-tds") # will read all sites' data -#' read_L2(variable = "gw-tds", path = "/path/to/L2/data") +#' read_L2_variable("gw-tds", site = "TMP") +#' read_L2_variable("gw-tds", c("TMP", "OWC")) # multiple sites +#' read_L2_variable(variable = "gw-tds") # will read all sites' data +#' read_L2_variable(variable = "gw-tds", path = "/path/to/L2/data") #' } -read_L2 <- function(variable, path, site = NULL, quiet = FALSE) { +read_L2_variable <- function(variable, path, site = NULL, quiet = FALSE) { if(length(variable) > 1) { stop("Only one variable can be read at a time") diff --git a/man/read_L1.Rd b/man/read_L1_variable.Rd similarity index 63% rename from man/read_L1.Rd rename to man/read_L1_variable.Rd index ca9e578..4f21a11 100644 --- a/man/read_L1.Rd +++ b/man/read_L1_variable.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\name{read_L1} -\alias{read_L1} +% Please edit documentation in R/read_Lx_variable.R +\name{read_L1_variable} +\alias{read_L1_variable} \title{Read L1 (Level 1) sensor data files} \usage{ -read_L1(variable, path, site = NULL, quiet = FALSE) +read_L1_variable(variable, path, site = NULL, quiet = FALSE) } \arguments{ \item{variable}{Variable name ('research name') to be read, character} @@ -28,10 +28,10 @@ This function only works for L1 v2-0 (July 2025) and higher. } \examples{ \dontrun{ -read_L1("gw-tds", site = "TMP") -read_L1("gw-tds", c("TMP", "OWC")) # multiple sites -read_L1(variable = "gw-tds") # will read all sites' data -read_L1(variable = "gw-tds", path = "/path/to/L1/data") +read_L1_variable("gw-tds", site = "TMP") +read_L1_variable("gw-tds", c("TMP", "OWC")) # multiple sites +read_L1_variable(variable = "gw-tds") # will read all sites' data +read_L1_variable(variable = "gw-tds", path = "/path/to/L1/data") } } \author{ diff --git a/man/read_L2.Rd b/man/read_L2_variable.Rd similarity index 63% rename from man/read_L2.Rd rename to man/read_L2_variable.Rd index cca5caf..db29523 100644 --- a/man/read_L2.Rd +++ b/man/read_L2_variable.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\name{read_L2} -\alias{read_L2} +% Please edit documentation in R/read_Lx_variable.R +\name{read_L2_variable} +\alias{read_L2_variable} \title{Read L2 (Level 2) sensor data files (Parquet format)} \usage{ -read_L2(variable, path, site = NULL, quiet = FALSE) +read_L2_variable(variable, path, site = NULL, quiet = FALSE) } \arguments{ \item{variable}{Variable name ('research name') to be read, character} @@ -28,10 +28,10 @@ This function only works for L2 v2-0 (July 2025) and higher. } \examples{ \dontrun{ -read_L2("gw-tds", site = "TMP") -read_L2("gw-tds", c("TMP", "OWC")) # multiple sites -read_L2(variable = "gw-tds") # will read all sites' data -read_L2(variable = "gw-tds", path = "/path/to/L2/data") +read_L2_variable("gw-tds", site = "TMP") +read_L2_variable("gw-tds", c("TMP", "OWC")) # multiple sites +read_L2_variable(variable = "gw-tds") # will read all sites' data +read_L2_variable(variable = "gw-tds", path = "/path/to/L2/data") } } \author{ diff --git a/tests/testthat/test-read_Lx.R b/tests/testthat/test-read_Lx.R index cc4e865..ad38d37 100644 --- a/tests/testthat/test-read_Lx.R +++ b/tests/testthat/test-read_Lx.R @@ -1,46 +1,46 @@ -# read_Lx functions +# read_Lx_variable functions -test_that("read_L1 works", { +test_that("read_L1_variable works", { # Handles bad input - expect_error(read_L1(letters[1:2]), regexp = "Only one variable") + expect_error(read_L1_variable(letters[1:2]), regexp = "Only one variable") # Single site - x <- read_L1(variable = "gw-tds", path = "./test_data", site = "TMP", quiet = TRUE) + x <- read_L1_variable(variable = "gw-tds", path = "./test_data", site = "TMP", quiet = TRUE) expect_s3_class(x, "data.frame") expect_true(all(x$Site == "TMP")) # Multiple sites - x <- read_L1(variable = "gw-tds", path = "./test_data", quiet = TRUE) + x <- read_L1_variable(variable = "gw-tds", path = "./test_data", quiet = TRUE) expect_s3_class(x, "data.frame") expect_true(length(unique(x$Site)) > 1) # Respects quiet flag - expect_no_message(read_L1(variable = "gw-tds", path = "./test_data", quiet = TRUE)) + expect_no_message(read_L1_variable(variable = "gw-tds", path = "./test_data", quiet = TRUE)) # Warns if no files found - expect_warning(read_L1("A", path = "./test_data", quiet = TRUE), + expect_warning(read_L1_variable("A", path = "./test_data", quiet = TRUE), regexp = "No files found") }) -test_that("read_L2 works", { +test_that("read_L2_variable works", { # Handles bad input - expect_error(read_L2(letters[1:2]), regexp = "Only one variable") + expect_error(read_L2_variable(letters[1:2]), regexp = "Only one variable") # Single site - x <- read_L2(variable = "sonde-fdom-rfu", path = "./test_data", site = "OWC", quiet = TRUE) + x <- read_L2_variable(variable = "sonde-fdom-rfu", path = "./test_data", site = "OWC", quiet = TRUE) expect_s3_class(x, "data.frame") expect_true(all(x$Site == "OWC")) # Multiple sites - x <- read_L2(variable = "sonde-fdom-rfu", path = "./test_data", quiet = TRUE) + x <- read_L2_variable(variable = "sonde-fdom-rfu", path = "./test_data", quiet = TRUE) expect_s3_class(x, "data.frame") expect_true(length(unique(x$Site)) > 1) # Respects quiet flag - expect_no_message(read_L2(variable = "sonde-fdom-rfu", path = "./test_data", quiet = TRUE)) + expect_no_message(read_L2_variable(variable = "sonde-fdom-rfu", path = "./test_data", quiet = TRUE)) # Warns if no files found - expect_warning(read_L2("A", path = "./test_data", quiet = TRUE), + expect_warning(read_L2_variable("A", path = "./test_data", quiet = TRUE), regexp = "No files found") }) From 0c53a1a88a074a22c2f3ad90a7757a93982d1ed1 Mon Sep 17 00:00:00 2001 From: Ben Bond-Lamberty Date: Wed, 11 Feb 2026 05:30:53 -0500 Subject: [PATCH 6/6] Update read_Lx_variable.R --- R/read_Lx_variable.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/read_Lx_variable.R b/R/read_Lx_variable.R index fa1c01f..41c789b 100644 --- a/R/read_Lx_variable.R +++ b/R/read_Lx_variable.R @@ -37,7 +37,7 @@ read_L1_variable <- function(variable, path, site = NULL, quiet = FALSE) { sites <- paste0("(", paste(site, collapse = "|"), ")") } # Construct regular expression to identify files - regex <- paste0("^", sites, "_[A-Z]+_.*_", variable, "_L1_.*csv$") + regex <- paste0("^", sites, "_[A-Z0-9]+_.*_", variable, "_L1_.*csv$") if(!quiet) message(regex) files <- list.files(path, pattern = regex, recursive = TRUE) if(!quiet) message("Reading ", length(files), " files") @@ -89,7 +89,7 @@ read_L2_variable <- function(variable, path, site = NULL, quiet = FALSE) { sites <- paste0("(", paste(site, collapse = "|"), ")") } # Construct regular expression to identify files - regex <- paste0("^", sites, "_[A-Z]+_.*_", variable, "_L2_.*parquet$") + regex <- paste0("^", sites, "_[A-Z0-9]+_.*_", variable, "_L2_.*parquet$") if(!quiet) message(regex) files <- list.files(path, pattern = regex, recursive = TRUE) if(!quiet) message("Reading ", length(files), " files")