diff --git a/R/calibrate_ambient_water_isotopes.R b/R/calibrate_ambient_water_isotopes.R index c95015b..fafa39d 100644 --- a/R/calibrate_ambient_water_isotopes.R +++ b/R/calibrate_ambient_water_isotopes.R @@ -67,7 +67,7 @@ calibrate_ambient_water_linreg <- function(amb_data_list, # determine which cal period each ambient data belongs to. var_inds_in_calperiod <- list() - for (i in 1:nrow(caldf)) { + for (i in seq_len(nrow(caldf))) { int <- lubridate::interval(caldf$timeBgn[i], caldf$timeEnd[i]) var_inds_in_calperiod[[i]] <- which(amb_end_times %within% int) } @@ -76,7 +76,7 @@ calibrate_ambient_water_linreg <- function(amb_data_list, oxydf$mean_cal <- oxydf$mean oxydf$max_cal <- oxydf$max oxydf$min_cal <- oxydf$min - + for (i in 1:length(var_inds_in_calperiod)) { if (!is.na(caldf$r2_18O[i]) & caldf$r2_18O[i] > r2_thres) { diff --git a/R/calibrate_carbon.R b/R/calibrate_carbon.R index b1cd8f4..52049a4 100644 --- a/R/calibrate_carbon.R +++ b/R/calibrate_carbon.R @@ -199,30 +199,29 @@ calibrate_carbon <- function(inname, ciso_subset_cal <- lapply(names(ciso_subset), - function(x) { - calibrate_ambient_carbon_Bowling2003( - amb_data_list = ciso_subset[[x]], - caldf = cal_df, - site = site, - filter_data = filter_ambient, - force_to_end = force_cal_to_end, - force_to_beginning = force_cal_to_beginning, - r2_thres = r2_thres) - }) + function(x) { + calibrate_ambient_carbon_Bowling2003(amb_data_list = ciso_subset[[x]], + caldf = cal_df, + site = site, + filter_data = filter_ambient, + force_to_end = force_cal_to_end, + force_to_beginning = force_cal_to_beginning, + r2_thres = r2_thres) + }) } else if (method == "linreg") { - ciso_subset_cal <- lapply(names(ciso_subset), - function(x) { - calibrate_ambient_carbon_linreg( - amb_data_list = ciso_subset[[x]], - caldf = cal_df, - site = site, - filter_data = filter_ambient, - force_to_end = force_cal_to_end, - force_to_beginning = force_cal_to_beginning, - r2_thres = r2_thres) - }) + ciso_subset_cal <- + lapply(names(ciso_subset), + function(x) { + calibrate_ambient_carbon_linreg(amb_data_list = ciso_subset[[x]], + caldf = cal_df, + site = site, + filter_data = filter_ambient, + force_to_end = force_cal_to_end, + force_to_beginning = force_cal_to_beginning, + r2_thres = r2_thres) + }) } names(ciso_subset_cal) <- names(ciso_subset) diff --git a/R/excised.R b/R/excised.R index ce5e6ba..59e35d0 100644 --- a/R/excised.R +++ b/R/excised.R @@ -194,4 +194,4 @@ copy_ucrt_group <- function(data_list, outname, site, file, species) { } -# nocov end \ No newline at end of file +# nocov end diff --git a/tests/testthat/test-data_extraction.R b/tests/testthat/test-data_extraction.R index 1ccb431..fd59777 100644 --- a/tests/testthat/test-data_extraction.R +++ b/tests/testthat/test-data_extraction.R @@ -4,7 +4,7 @@ fin <- system.file("extdata", "NEON.D15.ONAQ.DP4.00200.001.nsae.2019-05.basic.packed.h5", - package = 'NEONiso', mustWork = TRUE) + package = "NEONiso", mustWork = TRUE) # 1) for CO2: co2test <- ingest_data(fin, analyte = "Co2", amb_avg = 9, ref_avg = 9) @@ -22,19 +22,19 @@ test_that("extract_carbon_calibration_data output has correct structure", { }) test_that("extract_carbon_calibration_data removes standards correctly", { - + expect_lt(nrow(extract_carbon_cal_data(co2test$refe_stacked, - standards = c("co2Low", "co2Med"))), - nrow(extract_carbon_cal_data(co2test$refe_stacked))) - + standards = c("co2Low", "co2Med"))), + nrow(extract_carbon_cal_data(co2test$refe_stacked))) + expect_lt(nrow(extract_carbon_cal_data(co2test$refe_stacked, - standards = c("co2Low", "co2High"))), - nrow(extract_carbon_cal_data(co2test$refe_stacked))) - + standards = c("co2Low", "co2High"))), + nrow(extract_carbon_cal_data(co2test$refe_stacked))) + expect_lt(nrow(extract_carbon_cal_data(co2test$refe_stacked, - standards = "co2Low")), - nrow(extract_carbon_cal_data(co2test$refe_stacked, - standards = c("co2High", "co2Med")))) + standards = "co2Low")), + nrow(extract_carbon_cal_data(co2test$refe_stacked, + standards = c("co2High", "co2Med")))) }) # 2) for H2O: @@ -55,36 +55,3 @@ test_that("extract_water_calibration_data output has correct structure", { expect_s3_class(tmp$timeBgn, "POSIXct") expect_s3_class(tmp$timeEnd, "POSIXct") }) - - -# wiso_ref <- neonUtilities::stackEddy(fin, level = "dp01", avg = 3) -# -# high <- subset(wiso_ref[["ONAQ"]], -# wiso_ref[["ONAQ"]]$verticalPosition == "h2oHigh") -# med <- subset(wiso_ref[["ONAQ"]], -# wiso_ref[["ONAQ"]]$verticalPosition == "h2oMed") -# low <- subset(wiso_ref[["ONAQ"]], -# wiso_ref[["ONAQ"]]$verticalPosition == "h2oLow") -# -# test_that("extract_water_calibration_data returns 16 columns for by_site method", { -# expect_equal(ncol(extract_water_calibration_data(high, -# standard = "high", -# method = "by_site")), 16) -# expect_equal(ncol(extract_water_calibration_data(med, -# standard = "med", -# method = "by_site")), 16) -# expect_equal(ncol(extract_water_calibration_data(low, -# standard = "low", -# method = "by_site")), 16) -# }) -# -# test_that("extract_water_calibration_data returns error if invalid standard provided", { -# expect_error(extract_water_calibration_data(low, -# standard = "cheese", -# method = "by_site")) -# expect_error(extract_water_calibration_data(low, -# standard = "cheese", -# method = "by_month")) -# }) -# - diff --git a/tests/testthat/test-data_ingestion.R b/tests/testthat/test-data_ingestion.R index 1717f36..d855a4c 100644 --- a/tests/testthat/test-data_ingestion.R +++ b/tests/testthat/test-data_ingestion.R @@ -19,12 +19,6 @@ fin <- system.file("extdata", #------------------------------------------ # various tests about output structure of ingest_data. -# TEMPORARY TESTS: -# expect failure if analyte = "H2o" -#test_that("ingest_data errors for H2o (TEMPORARY)", { -# expect_error(ingest_data(fin, analyte = "H2o")) -#}) - # a) get data co2test <- ingest_data(fin, analyte = "Co2", amb_avg = 9, ref_avg = 9) h2otest <- ingest_data(fin, analyte = "H2o", amb_avg = 9, ref_avg = 3) @@ -51,7 +45,9 @@ rest_raw <- neonUtilities::stackEddy(fin, avg = 9, level = "dp01")[[1]] %>% dplyr::select("verticalPosition", "timeBgn", "timeEnd", tidyselect::contains("isoCo2")) -rest_raw <- rest_raw[rowSums(is.na(rest_raw)) < 145, ] # Needed to remove merge error where times are slightly different between h2o and co2. +# Needed to remove merge error where times are +# slightly different between h2o and co2. +rest_raw <- rest_raw[rowSums(is.na(rest_raw)) < 145, ] test_that("restructure_carbon_variables errors when invalid mode provided", { expect_error(restructure_carbon_variables(rest_raw, @@ -117,6 +113,6 @@ test2 <- ingest_data(all_files, analyte = "Co2", amb_avg = 9, ref_avg = 9) test_that("stackEddy/ingest data works on multiple daily files", { # would expect number of rows to be larger in test2 than test 1: - expect_gt(nrow(test2$ambient$`000_010_09m`$dlta13CCo2), nrow(test1$ambient$`000_010_09m`$dlta13CCo2)) + expect_gt(nrow(test2$ambient$`000_010_09m`$dlta13CCo2), + nrow(test1$ambient$`000_010_09m`$dlta13CCo2)) }) - diff --git a/tests/testthat/test-data_regression.R b/tests/testthat/test-data_regression.R index 97760ff..21f3158 100644 --- a/tests/testthat/test-data_regression.R +++ b/tests/testthat/test-data_regression.R @@ -4,17 +4,20 @@ # CARBON FUNCTIONS #---------------------- -# test to make sure that the I/O structures across regression functions are correct. +# test to make sure that the I/O structures +# across regression functions are correct. fin <- system.file("extdata", "NEON.D15.ONAQ.DP4.00200.001.nsae.2019-05.basic.packed.h5", package = "NEONiso", mustWork = TRUE) co2test <- ingest_data(fin, analyte = "Co2", amb_avg = 9, ref_avg = 9) co2data <- NEONiso:::extract_carbon_cal_data(co2test$refe_stacked, - standards = c("co2Low", "co2Med", "co2High")) -calDf_B03 <- NEONiso:::fit_carbon_regression(co2data, + standards = c("co2Low", + "co2Med", + "co2High")) +caldf_b03 <- NEONiso:::fit_carbon_regression(co2data, method = "Bowling_2003", calibration_half_width = 2) -calDf_LR <- NEONiso:::fit_carbon_regression(co2data, +caldf_lr <- NEONiso:::fit_carbon_regression(co2data, method = "linreg", calibration_half_width = 2) @@ -32,8 +35,8 @@ test_that("fit_carbon_regression returns data.frame", { test_that("calibration data frames have 14 columns", { skip_on_cran() - expect_equal(ncol(calDf_B03), 14) - expect_equal(ncol(calDf_LR), 14) + expect_equal(ncol(caldf_b03), 14) + expect_equal(ncol(caldf_lr), 14) }) test_that("carbon calibration data frames correct even when no input data", { @@ -57,12 +60,12 @@ test_that("carbon calibration data frames correct even when no input data", { # test carbon - bowling ambient calibration temp <- calibrate_ambient_carbon_Bowling2003(co2test$ambient$`000_010_09m`, - calDf_B03, + caldf_b03, site = "ONAQ") temp_gf <- calibrate_ambient_carbon_Bowling2003(co2test$ambient$`000_010_09m`, - calDf_B03, - site = "ONAQ", - gap_fill_parameters = TRUE) + caldf_b03, + site = "ONAQ", + gap_fill_parameters = TRUE) test_that("calibrate_ambient_carbon_Bowling2003 returns a list",{ skip_on_cran() @@ -83,20 +86,22 @@ test_that("calibrate_ambient_carbon_Bowling2003 returns correct variables", { test_that("calibrated d13C values have been added to calibrate_ambient_cabron_Bowling2003 output", { skip_on_cran() - expect_gt(ncol(temp$dlta13CCo2), ncol(co2test$ambient$`000_010_09m`$dlta13CCo2)) - expect_gt(ncol(temp_gf$dlta13CCo2), ncol(co2test$ambient$`000_010_09m`$dlta13CCo2)) + expect_gt(ncol(temp$dlta13CCo2), + ncol(co2test$ambient$`000_010_09m`$dlta13CCo2)) + expect_gt(ncol(temp_gf$dlta13CCo2), + ncol(co2test$ambient$`000_010_09m`$dlta13CCo2)) }) # test carbon - linreg ambient calibration temp <- calibrate_ambient_carbon_linreg(co2test$ambient$`000_010_09m`, - calDf_LR, - site = "ONAQ") + caldf_lr, + site = "ONAQ") temp_gf <- calibrate_ambient_carbon_linreg(co2test$ambient$`000_010_09m`, - calDf_LR, - site = "ONAQ", - gap_fill_parameters = TRUE) + caldf_lr, + site = "ONAQ", + gap_fill_parameters = TRUE) -test_that("calibrate_ambient_carbon_linreg returns a list",{ +test_that("calibrate_ambient_carbon_linreg returns a list", { skip_on_cran() expect_equal(class(temp), "list") expect_equal(class(temp_gf), "list") @@ -115,8 +120,10 @@ test_that("calibrate_ambient_carbon_linreg returns correct variables", { test_that("calibrated d13C values have been added to calibrate_ambient_cabron_linreg output", { skip_on_cran() - expect_gt(ncol(temp$dlta13CCo2), ncol(co2test$ambient$`000_010_09m`$dlta13CCo2)) - expect_gt(ncol(temp_gf$dlta13CCo2), ncol(co2test$ambient$`000_010_09m`$dlta13CCo2)) + expect_gt(ncol(temp$dlta13CCo2), + ncol(co2test$ambient$`000_010_09m`$dlta13CCo2)) + expect_gt(ncol(temp_gf$dlta13CCo2), + ncol(co2test$ambient$`000_010_09m`$dlta13CCo2)) }) @@ -131,19 +138,19 @@ fin <- system.file("extdata", h2otest <- ingest_data(fin, analyte = "H2o", amb_avg = 9, ref_avg = 3) h2odata <- NEONiso:::extract_water_calibration_data(h2otest$refe_stacked) -calDf <- NEONiso:::fit_water_regression(h2odata, +caldf <- NEONiso:::fit_water_regression(h2odata, calibration_half_width = 2) test_that("fit_water_regression returns data.frame", { skip_on_cran() expect_s3_class(fit_water_regression(h2odata, - calibration_half_width = 2), + calibration_half_width = 2), "data.frame") }) test_that("calibration data frames have 14 columns", { skip_on_cran() - expect_equal(ncol(calDf), 14) + expect_equal(ncol(caldf), 14) }) @@ -151,15 +158,15 @@ test_that("calibration data frames have 14 columns", { # test carbon - bowling ambient calibration temp <- calibrate_ambient_water_linreg(h2otest$ambient$`000_010_09m`, - calDf, - site = "ONAQ") + caldf, + site = "ONAQ") # no gapfilling in the water functions yet! #temp_gf <- calibrate_ambient_water_linreg(h2otest$ambient$`000_010_09m`, # calDf, # site = "ONAQ", # gap_fill_parameters = TRUE) -test_that("calibrate_ambient_water_linreg returns a list",{ +test_that("calibrate_ambient_water_linreg returns a list", { skip_on_cran() str(temp) expect_equal(class(temp), "list") @@ -169,17 +176,16 @@ test_that("calibrate_ambient_water_linreg returns a list",{ test_that("calibrate_ambient_water_linreg returns correct variables", { skip_on_cran() vars <- c("dlta18OH2o", "dlta2HH2o", "pres", "presEnvHut", "rhEnvHut", - "rtioMoleDryH2o", "rtioMoleWetH2o", - "rtioMoleWetH2oEnvHut", "temp", "tempEnvHut") + "rtioMoleDryH2o", "rtioMoleWetH2o", + "rtioMoleWetH2oEnvHut", "temp", "tempEnvHut") expect_equal(names(temp), vars) - # expect_equal(names(temp_gf), vars) + #expect_equal(names(temp_gf), vars) }) test_that("calibrated water isotope values have been added to calibrate_ambient_water_linreg output", { skip_on_cran() - expect_gt(ncol(temp$dlta18OH2o), ncol(h2otest$ambient$`000_010_09m`$dlta18OH2o)) - expect_gt(ncol(temp$dlta2HH2o), ncol(h2otest$ambient$`000_010_09m`$dlta2HH2o)) + expect_gt(ncol(temp$dlta18OH2o), + ncol(h2otest$ambient$`000_010_09m`$dlta18OH2o)) + expect_gt(ncol(temp$dlta2HH2o), + ncol(h2otest$ambient$`000_010_09m`$dlta2HH2o)) }) - - - diff --git a/tests/testthat/test-high_level_functions.R b/tests/testthat/test-high_level_functions.R index 300ad39..61bbba2 100644 --- a/tests/testthat/test-high_level_functions.R +++ b/tests/testthat/test-high_level_functions.R @@ -21,29 +21,29 @@ test_that("calibrate_carbon returns no error", { skip_on_cran() # these tests could probably be made more useful!! expect_no_error(calibrate_carbon(fin, fout1, "ONAQ", - method = "Bowling_2003", - calibration_half_width = 0.5, - force_cal_to_beginning = TRUE, - force_cal_to_end = TRUE, - gap_fill_parameters = FALSE, - filter_ambient = TRUE, - r2_thres = 0.95, - correct_ref_data = TRUE, - write_to_file = TRUE)) + method = "Bowling_2003", + calibration_half_width = 0.5, + force_cal_to_beginning = TRUE, + force_cal_to_end = TRUE, + gap_fill_parameters = FALSE, + filter_ambient = TRUE, + r2_thres = 0.95, + correct_ref_data = TRUE, + write_to_file = TRUE)) expect_no_error(calibrate_carbon(fin, fout2, "ONAQ", - method = "linreg", - calibration_half_width = 0.5, - force_cal_to_beginning = TRUE, - force_cal_to_end = TRUE, - gap_fill_parameters = FALSE, - filter_ambient = TRUE, - r2_thres = 0.95, - correct_ref_data = TRUE, - write_to_file = TRUE)) + method = "linreg", + calibration_half_width = 0.5, + force_cal_to_beginning = TRUE, + force_cal_to_end = TRUE, + gap_fill_parameters = FALSE, + filter_ambient = TRUE, + r2_thres = 0.95, + correct_ref_data = TRUE, + write_to_file = TRUE)) # these tests could probably be made more useful!! - expect_no_error(calibrate_carbon(fin, '/dev/null', "ONAQ", + expect_no_error(calibrate_carbon(fin, "/dev/null", "ONAQ", method = "Bowling_2003", calibration_half_width = 0.5, force_cal_to_beginning = TRUE, @@ -62,9 +62,9 @@ test_that("calibrate_water returns no error", { skip_on_cran() # these tests could probably be made more useful!! - expect_no_error(calibrate_water(fin, '/dev/null', "ONAQ", - correct_ref_data = TRUE, - write_to_file = FALSE)) + expect_no_error(calibrate_water(fin, "/dev/null", "ONAQ", + correct_ref_data = TRUE, + write_to_file = FALSE)) expect_no_error(calibrate_water(fin, fout3, "ONAQ", correct_ref_data = TRUE, diff --git a/tests/testthat/test-output_values.R b/tests/testthat/test-output_values.R index 8d784fa..1e1a89b 100644 --- a/tests/testthat/test-output_values.R +++ b/tests/testthat/test-output_values.R @@ -1,19 +1,22 @@ # test-output_values.R -# need to add some tests to validate output data, as there are clearly some issues +# need to add some tests to validate output data, +# as there are clearly some issues # remaining with calibration - trying to figure out why fin <- system.file("extdata", "NEON.D12.YELL.DP4.00200.001.nsae.2020-11.basic.packed.h5", package = "NEONiso", mustWork = TRUE) -co2test <- NEONiso:::ingest_data(fin, analyte = 'Co2', ref_avg = 9, amb_avg = 9) +co2test <- NEONiso:::ingest_data(fin, analyte = "Co2", ref_avg = 9, amb_avg = 9) co2data <- NEONiso:::extract_carbon_cal_data(co2test$refe_stacked, - standards = c("co2Low", "co2Med", "co2High")) -calDf_B03 <- NEONiso:::fit_carbon_regression(co2data, + standards = c("co2Low", + "co2Med", + "co2High")) +caldf_b03 <- NEONiso:::fit_carbon_regression(co2data, method = "Bowling_2003", calibration_half_width = 2) -calDf_LR <- NEONiso:::fit_carbon_regression(co2data, +caldf_lr <- NEONiso:::fit_carbon_regression(co2data, method = "linreg", calibration_half_width = 2) @@ -21,50 +24,64 @@ ciso_subset <- co2test$ambient ciso_subset_cal <- lapply(names(ciso_subset), function(x) { - calibrate_ambient_carbon_Bowling2003( - amb_data_list = ciso_subset[[x]], - caldf = calDf_B03, - site = "YELL", - filter_data = TRUE, - force_to_end = TRUE, - force_to_beginning = TRUE, - r2_thres = 0.9) + calibrate_ambient_carbon_Bowling2003(amb_data_list = ciso_subset[[x]], + caldf = caldf_b03, + site = "YELL", + filter_data = TRUE, + force_to_end = TRUE, + force_to_beginning = TRUE, + r2_thres = 0.9) }) names(ciso_subset_cal) <- names(ciso_subset) test_that("calibrated ambient co2 delta values in B03 are within a plausible range", { - expect_lt(max(ciso_subset_cal$`000_010_09m`$dlta13CCo2$mean_cal, na.rm = TRUE), 10) - expect_gt(min(ciso_subset_cal$`000_010_09m`$dlta13CCo2$mean_cal, na.rm = TRUE), -50) + expect_lt(max(ciso_subset_cal$`000_010_09m`$dlta13CCo2$mean_cal, + na.rm = TRUE), + 10) + expect_gt(min(ciso_subset_cal$`000_010_09m`$dlta13CCo2$mean_cal, + na.rm = TRUE), + -50) }) test_that("calibrated ambient co2 mixing ratios in B03 are within a plausible range", { - expect_lt(max(ciso_subset_cal$`000_010_09m`$rtioMoleDryCo2$mean_cal, na.rm = TRUE), 1500) - expect_gt(min(ciso_subset_cal$`000_010_09m`$rtioMoleDryCo2$mean_cal, na.rm = TRUE), 300) + expect_lt(max(ciso_subset_cal$`000_010_09m`$rtioMoleDryCo2$mean_cal, + na.rm = TRUE), + 1500) + expect_gt(min(ciso_subset_cal$`000_010_09m`$rtioMoleDryCo2$mean_cal, + na.rm = TRUE), + 300) }) ciso_subset_cal <- lapply(names(ciso_subset), function(x) { - calibrate_ambient_carbon_linreg( - amb_data_list = ciso_subset[[x]], - caldf = calDf_LR, - site = "YELL", - filter_data = TRUE, - force_to_end = TRUE, - force_to_beginning = TRUE, - r2_thres = 0.9) + calibrate_ambient_carbon_linreg(amb_data_list = ciso_subset[[x]], + caldf = caldf_lr, + site = "YELL", + filter_data = TRUE, + force_to_end = TRUE, + force_to_beginning = TRUE, + r2_thres = 0.9) }) names(ciso_subset_cal) <- names(ciso_subset) test_that("calibrated carbon values linreg are within a plausible range", { - expect_lt(max(ciso_subset_cal$`000_010_09m`$dlta13CCo2$mean_cal, na.rm = TRUE), 10) - expect_gt(min(ciso_subset_cal$`000_010_09m`$dlta13CCo2$mean_cal, na.rm = TRUE), -50) + expect_lt(max(ciso_subset_cal$`000_010_09m`$dlta13CCo2$mean_cal, + na.rm = TRUE), + 10) + expect_gt(min(ciso_subset_cal$`000_010_09m`$dlta13CCo2$mean_cal, + na.rm = TRUE), + -50) }) test_that("calibrated ambient co2 mixing ratios linreg are within a plausible range", { - expect_lt(max(ciso_subset_cal$`000_010_09m`$rtioMoleDryCo2$mean_cal, na.rm = TRUE), 1500) - expect_gt(min(ciso_subset_cal$`000_010_09m`$rtioMoleDryCo2$mean_cal, na.rm = TRUE), 300) + expect_lt(max(ciso_subset_cal$`000_010_09m`$rtioMoleDryCo2$mean_cal, + na.rm = TRUE), + 1500) + expect_gt(min(ciso_subset_cal$`000_010_09m`$rtioMoleDryCo2$mean_cal, + na.rm = TRUE), + 300) }) diff --git a/tests/testthat/test-standard_corrections.R b/tests/testthat/test-standard_corrections.R index 2f7017c..6d4f8b7 100644 --- a/tests/testthat/test-standard_corrections.R +++ b/tests/testthat/test-standard_corrections.R @@ -18,9 +18,9 @@ test_that("unreasonable d-excess values get swapped", { }) test_vals <- c(0, -5, -10, -20, -30) -test_RC <- delta_to_R(test_vals[3], "carbon") -test_RO <- delta_to_R(test_vals[3], "oxygen") -test_RH <- delta_to_R(test_vals[3], "hydrogen") +test_rc <- delta_to_R(test_vals[3], "carbon") +test_ro <- delta_to_R(test_vals[3], "oxygen") +test_rh <- delta_to_R(test_vals[3], "hydrogen") test_that("R_to_delta and delta_to_R are invertible", { expect_equal(R_to_delta(delta_to_R(mlo$d13c, "carbon"), @@ -41,15 +41,15 @@ test_that("R values are < 1", { }) test_that("delta values are < 50", { - expect_lt(R_to_delta(test_RC, "carbon"), 50) - expect_lt(R_to_delta(test_RO, "oxygen"), 50) - expect_lt(R_to_delta(test_RH, "hydrogen"), 50) + expect_lt(R_to_delta(test_rc, "carbon"), 50) + expect_lt(R_to_delta(test_ro, "oxygen"), 50) + expect_lt(R_to_delta(test_rh, "hydrogen"), 50) }) test_that("delta values are > -1000", { - expect_gte(R_to_delta(test_RC, "carbon"), -1000) - expect_gte(R_to_delta(test_RO, "oxygen"), -1000) - expect_gte(R_to_delta(test_RH, "hydrogen"), -1000) + expect_gte(R_to_delta(test_rc, "carbon"), -1000) + expect_gte(R_to_delta(test_ro, "oxygen"), -1000) + expect_gte(R_to_delta(test_rh, "hydrogen"), -1000) }) test_that("12co2 calculations work", { diff --git a/tests/testthat/test-utility_functions.R b/tests/testthat/test-utility_functions.R index bc20d42..0b9ae50 100644 --- a/tests/testthat/test-utility_functions.R +++ b/tests/testthat/test-utility_functions.R @@ -1,18 +1,17 @@ # test time conversion function -test_that("convert_POSIXct_to_NEONhdf5_time returns a string 24 characters long", { +test_that("convert_POSIXct_to_NEONhdf5_time returns 24 character string", { expect_type(convert_POSIXct_to_NEONhdf5_time(Sys.time()), "character") expect_equal(nchar(convert_POSIXct_to_NEONhdf5_time(Sys.time())), 24) }) - test_that("site retrieval functions return vector of strings", { expect_type(terrestrial_core_sites(), "character") expect_type(terrestrial_gradient_sites(), "character") expect_type(water_isotope_sites(), "character") }) -test_that("correct number of sites in each site retrieval function vector",{ +test_that("correct number of sites in each site retrieval function vector", { expect_equal(length(terrestrial_core_sites()), 20) expect_equal(length(terrestrial_gradient_sites()), 27) expect_equal(length(water_isotope_sites()), 21) -}) \ No newline at end of file +}) diff --git a/vignettes/example_workflow.Rmd b/vignettes/example_workflow.Rmd index 6906364..ce9fc55 100644 --- a/vignettes/example_workflow.Rmd +++ b/vignettes/example_workflow.Rmd @@ -46,20 +46,20 @@ The simplest way to interact with these functions is to place it inside of a for ``` {r, eval = FALSE} -for (i in 1:length(fnames.out)) { +for (i in seq_along(fnames_out)) { calibrate_carbon_bymonth(fnames[i], - fnames.out[i], - site=site.code[i], + fnames_out[i], + site = site_code[i], method = "Bowling_2003") } ``` -Two different methods to calibrate are available: a) a 'gain and offset' regression using 12CO2 and 13CO2 mole fractions (method = 'Bowling_2003', after Bowling et al. 2003) and b) a 'direct' linear regression of CO2 and d13C values to generate calibration transfer functions (method = 'linreg'). The function 'calibrate_carbon_bymonth()' assumes you have vectors of: 1) input file names (fnames), 2) output file names (fnames.out), and 3) 4 letter NEON site codes corresponding to each entry in input file names (fnames). An example of code to generate these three vectors is provided below: +Two different methods to calibrate are available: a) a 'gain and offset' regression using 12CO2 and 13CO2 mole fractions (method = 'Bowling_2003', after Bowling et al. 2003) and b) a 'direct' linear regression of CO2 and d13C values to generate calibration transfer functions (method = 'linreg'). The function 'calibrate_carbon_bymonth()' assumes you have vectors of: 1) input file names (fnames), 2) output file names (fnames.out), and 3) 4 letter NEON site codes corresponding to each entry in input file names (fnames). An example of code to generate these three vectors is provided below: ```{r, eval = FALSE} -data.dir <- "/your/path/here/DP4_00200_001/" +data_dir <- "/your/path/here/DP4_00200_001/" -fnames <- list.files(path = data.dir, +fnames <- list.files(path = data_dir, pattern = ".h5", recursive = TRUE, full.names = TRUE) @@ -67,19 +67,19 @@ fnames <- list.files(path = data.dir, # unselect gz files. fnames <- fnames[!grepl(".gz", fnames)] -fname.byfolder <- strsplit(fnames, split=".", fixed = TRUE) -site.code <- sapply(fname.byfolder, "[[", 3) +fname_byfolder <- strsplit(fnames, split = ".", fixed = TRUE) +site_code <- sapply(fname_byfolder, "[[", 3) # inspect site.code in the environment: is it a vector with repeated "ONAQ"? -fnames.tmp <- gsub(".h5", ".calibrated.h5", fnames) -fnames.spt <- strsplit(fnames.tmp, split = "/") -fnames.out <- sapply(fnames.spt, "[[", 7) +fnames_tmp <- gsub(".h5", ".calibrated.h5", fnames) +fnames_spt <- strsplit(fnames_tmp, split = "/") +fnames_out <- sapply(fnames_spt, "[[", 7) # create new output directory outpaths <- paste0(your_path, "/ONAQ/output/") # apply function used here to generalize in case you wanted to run all sites -sapply(unique(outpaths), dir.create, showWarnings=FALSE) +sapply(unique(outpaths), dir.create, showWarnings = FALSE) # update fnames.out to include desired output paths. -fnames.out <- paste0(outpaths, "/", fnames.out) +fnames_out <- paste0(outpaths, "/", fnames_out) ```