From 6cd46c7dea2a4850d8f2fac899084a9cd7bdf870 Mon Sep 17 00:00:00 2001 From: Rich Fiorella Date: Sun, 29 Dec 2024 08:51:13 -0700 Subject: [PATCH] lintr cleanup for 0.7.1 --- R/calibrate_ambient_carbon_gainoffset.R | 20 +-- R/calibrate_ambient_carbon_linreg.R | 8 +- R/calibrate_ambient_water_isotopes.R | 10 +- R/calibrate_carbon.R | 5 +- R/excised.R | 197 ------------------------ R/isotope_conversions.R | 14 +- R/output_functions.R | 10 +- R/quality_control.R | 14 +- R/reference_data_extraction.R | 8 +- R/reference_data_regression.R | 28 ++-- R/restructure_data.R | 6 +- R/time_functions.R | 4 +- R/utility_functions.R | 16 +- man/write_carbon_calibration_data.Rd | 4 +- man/write_water_calibration_data.Rd | 4 +- 15 files changed, 76 insertions(+), 272 deletions(-) delete mode 100644 R/excised.R diff --git a/R/calibrate_ambient_carbon_gainoffset.R b/R/calibrate_ambient_carbon_gainoffset.R index 49c3ee9..1fea2c3 100644 --- a/R/calibrate_ambient_carbon_gainoffset.R +++ b/R/calibrate_ambient_carbon_gainoffset.R @@ -1,5 +1,5 @@ calibrate_ambient_carbon_Bowling2003 <- function(...) { - lifecycle::deprecate_soft("0.7.1","calibrate_ambient_carbon_Bowling2003()", + lifecycle::deprecate_soft("0.7.1", "calibrate_ambient_carbon_Bowling2003()", "calibrate_ambient_carbon_gainoffset()") calibrate_ambient_carbon_gainoffset(...) } @@ -44,13 +44,13 @@ calibrate_ambient_carbon_Bowling2003 <- function(...) { #' @importFrom lubridate %within% #' calibrate_ambient_carbon_gainoffset <- function(amb_data_list, - caldf, - site, - filter_data = TRUE, - force_to_end = TRUE, - force_to_beginning = TRUE, - gap_fill_parameters = FALSE, - r2_thres = 0.9) { + caldf, + site, + filter_data = TRUE, + force_to_end = TRUE, + force_to_beginning = TRUE, + gap_fill_parameters = FALSE, + r2_thres = 0.9) { #----------------------------------------------------------- # should be able to get a calGainsOffsets object from the H5 file. @@ -108,7 +108,7 @@ calibrate_ambient_carbon_gainoffset <- function(amb_data_list, # print notice that we're gap filling print("Gap filling calibrations...") # 12CO2 calibration parameters. - if (!is.na(caldf$r2_12C[i]) & caldf$r2_12C[i] < r2_thres) { + if (!is.na(caldf$r2_12C[i]) && caldf$r2_12C[i] < r2_thres) { # if we're in calibration period 2 or later, carry previous # calibration period forward. else if the first calibration period # is bad, find the first good calibration period at index n, @@ -126,7 +126,7 @@ calibrate_ambient_carbon_gainoffset <- function(amb_data_list, } # 13CO2 calibration parameters - equivalent logic to 12Co2. - if (!is.na(caldf$r2_13C[i]) & caldf$r2_13C[i] < r2_thres) { + if (!is.na(caldf$r2_13C[i]) && caldf$r2_13C[i] < r2_thres) { if (i > 1) { caldf$gain13C[i] <- caldf$gain13C[i - 1] caldf$offset13C[i] <- caldf$offset13C[i - 1] diff --git a/R/calibrate_ambient_carbon_linreg.R b/R/calibrate_ambient_carbon_linreg.R index ceadc77..31b68f7 100644 --- a/R/calibrate_ambient_carbon_linreg.R +++ b/R/calibrate_ambient_carbon_linreg.R @@ -71,7 +71,7 @@ calibrate_ambient_carbon_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) @@ -80,7 +80,7 @@ calibrate_ambient_carbon_linreg <- function(amb_data_list, # print notice that we're gap filling print("Gap filling calibrations...") - if (!is.na(caldf$d13C_r2[i]) & caldf$d13C_r2[i] < r2_thres) { + if (!is.na(caldf$d13C_r2[i]) && caldf$d13C_r2[i] < r2_thres) { # if we're in calibration period 2 or later, carry previous # calibration period forward. else if the first calibration period # is bad, find the first good calibration period at index n, @@ -98,7 +98,7 @@ calibrate_ambient_carbon_linreg <- function(amb_data_list, } # apply same logic to CO2 calibration. - if (!is.na(caldf$co2_r2[i]) & caldf$co2_r2[i] < r2_thres) { + if (!is.na(caldf$co2_r2[i]) && caldf$co2_r2[i] < r2_thres) { if (i > 1) { caldf$co2_slope[i] <- caldf$co2_slope[i - 1] caldf$co2_intercept[i] <- caldf$co2_intercept[i - 1] @@ -128,7 +128,7 @@ calibrate_ambient_carbon_linreg <- function(amb_data_list, co2_ambdf$cv5rmse <- rep(NA, length(co2_ambdf$mean)) co2_ambdf$cv5mae <- rep(NA, length(co2_ambdf$mean)) - for (i in 1:length(var_inds_in_calperiod)) { + for (i in seq_along(var_inds_in_calperiod)) { d13c_ambdf$mean_cal[var_inds_in_calperiod[[i]]] <- caldf$d13C_intercept[i] + d13c_ambdf$mean[var_inds_in_calperiod[[i]]] * caldf$d13C_slope[i] diff --git a/R/calibrate_ambient_water_isotopes.R b/R/calibrate_ambient_water_isotopes.R index fafa39d..7dbcdb8 100644 --- a/R/calibrate_ambient_water_isotopes.R +++ b/R/calibrate_ambient_water_isotopes.R @@ -77,8 +77,8 @@ calibrate_ambient_water_linreg <- function(amb_data_list, 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) { + for (i in seq_along(var_inds_in_calperiod)) { + if (!is.na(caldf$r2_18O[i]) && caldf$r2_18O[i] > r2_thres) { oxydf$mean_cal[var_inds_in_calperiod[[i]]] <- caldf$intercept18O[i] + oxydf$mean[var_inds_in_calperiod[[i]]] * caldf$slope18O[i] @@ -129,7 +129,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) } @@ -138,9 +138,9 @@ calibrate_ambient_water_linreg <- function(amb_data_list, hyddf$max_cal <- hyddf$max hyddf$min_cal <- hyddf$min - for (i in 1:length(var_inds_in_calperiod)) { + for (i in seq_along(var_inds_in_calperiod)) { - if (!is.na(caldf$r2_2H[i]) & caldf$r2_2H[i] > r2_thres) { + if (!is.na(caldf$r2_2H[i]) && caldf$r2_2H[i] > r2_thres) { hyddf$mean_cal[var_inds_in_calperiod[[i]]] <- caldf$intercept2H[i] + hyddf$mean[var_inds_in_calperiod[[i]]] * caldf$slope2H[i] diff --git a/R/calibrate_carbon.R b/R/calibrate_carbon.R index 6adeeb5..2ac3d24 100644 --- a/R/calibrate_carbon.R +++ b/R/calibrate_carbon.R @@ -147,9 +147,10 @@ calibrate_carbon <- function(inname, inname <- inname[!grepl("2019-07", inname)] } } - + if (method == "Bowling_2003") { - lifecycle::deprecate_warn("0.7.1","calibrate_carbon(method = 'Bowling_2003')", + lifecycle::deprecate_warn("0.7.1", + "calibrate_carbon(method = 'Bowling_2003')", "calibrate_carbon(method = 'gainoffset')") } diff --git a/R/excised.R b/R/excised.R deleted file mode 100644 index c4d1104..0000000 --- a/R/excised.R +++ /dev/null @@ -1,197 +0,0 @@ -# nocov start - -#' write_qfqm -#' -#' Write NEON's qfqm data for an isotope species to -#' output file. Wraps copy_qfqm_group. -#' -#' @author Rich Fiorella \email{rfiorella@@lanl.gov} -#' -#' @param inname Input file name. -#' @param outname Output file name. -#' @param site NEON 4-letter site code. -#' @param analyte Carbon ('Co2') or water ('H2o') system? -#' -#' @return Nothing to the environment, but writes qfqm data to file. -#' -# write_qfqm <- function(inname, outname, site, analyte) { -# -# analyte <- validate_analyte(analyte) -# -# print("Copying qfqm...") -# # copy over ucrt and qfqm groups as well. -# rhdf5::h5createGroup(outname, paste0("/", site, "/dp01/qfqm/")) -# rhdf5::h5createGroup(outname, paste0("/", site, "/dp01/qfqm/iso", analyte)) -# qfqm <- rhdf5::h5read(inname, paste0("/", site, "/dp01/qfqm/iso", analyte)) -# -# lapply(names(qfqm), -# function(x) { -# copy_qfqm_group(data_list = qfqm[[x]], -# outname = x, -# file = outname, -# site = site, -# species = analyte) -# }) -# -# rhdf5::h5closeAll() -# -# } - -#' write_ucrt -#' -#' Write NEON's ucrt data for an isotope species to -#' output file. Wraps copy_ucrt_group. -#' -#' @author Rich Fiorella \email{rfiorella@@lanl.gov} -#' -#' @param inname Input file name. -#' @param outname Output file name. -#' @param site NEON 4-letter site code. -#' @param analyte Carbon ('Co2') or water ('H2o') system? -#' -#' @return Nothing to the environment, but writes ucrt data to file. -#' -# write_ucrt <- function(inname, outname, site, analyte) { -# -# analyte <- validate_analyte(analyte) -# -# print("Copying ucrt...") -# # copy over ucrt and qfqm groups as well. -# rhdf5::h5createGroup(outname, paste0("/", site, "/dp01/ucrt/")) -# rhdf5::h5createGroup(outname, paste0("/", site, "/dp01/ucrt/iso", analyte)) -# ucrt <- rhdf5::h5read(inname, paste0("/", site, "/dp01/ucrt/iso", analyte)) -# -# lapply(names(ucrt), -# function(x) { -# copy_ucrt_group(data_list = ucrt[[x]], -# outname = x, -# file = outname, -# site = site, -# species = analyte) -# }) -# -# rhdf5::h5closeAll() -# -# } - -#' copy_qfqm_group -#' -#' @author Rich Fiorella \email{rfiorella@@lanl.gov} -#' -#' @param data_list List of groups to retrieve qfqm data from. -#' @param outname Output filename. -#' @param site Four-letter NEON site code. -#' @param file Input filename. -#' @param species CO2 or H2O? Same function used for both CO2 and H2O isotopes. -#' -#' @return Nothing to the workspace, but copies qfqm group from input file to -#' output file. -#' -#' copy_qfqm_group <- function(data_list, outname, site, file, species) { -#' -#' # create hdf5 structure for these variables. -#' fid <- rhdf5::H5Fopen(file) -#' -#' if (species == "Co2") { -#' co2_data_outloc <- rhdf5::H5Gcreate(fid, -#' paste0("/", -#' site, -#' "/dp01/qfqm/isoCo2/", -#' outname)) -#' -#' # loop through each of the variables in list amb.data.list -#' # and write out as a dataframe. -#' lapply(names(data_list), -#' function(x) { -#' rhdf5::h5writeDataset(obj = data_list[[x]], -#' h5loc = co2_data_outloc, -#' name = x, -#' DataFrameAsCompound = TRUE) -#' }) -#' -#' } else if (species == "H2o") { -#' -#' h2o_data_outloc <- rhdf5::H5Gcreate(fid, -#' paste0("/", -#' site, -#' "/dp01/qfqm/isoH2o/", -#' outname)) -#' -#' # loop through each of the variables in list amb.data.list -#' # and write out as a dataframe. -#' lapply(names(data_list), -#' function(x) { -#' rhdf5::h5writeDataset(obj = data_list[[x]], -#' h5loc = h2o_data_outloc, -#' name = x, -#' DataFrameAsCompound = TRUE) -#' }) -#' -#' } -#' -#' # close all open handles. -#' rhdf5::h5closeAll() -#' -#' } -#' -#' #' copy_ucrt_group -#' #' -#' #' @author Rich Fiorella \email{rfiorella@@lanl.gov} -#' #' -#' #' @param outname Output file name. -#' #' @param site NEON 4-letter site code. -#' #' @param file Input file name. -#' #' @param data_list List of groups to retrieve ucrt data from. -#' #' @param species H2O or CO2. -#' #' -#' #' @return Nothing to the workspace, but copies ucrt group from input file to -#' #' output file. -#' #' -#' copy_ucrt_group <- function(data_list, outname, site, file, species) { -#' -#' # create hdf5 structure for these variables. -#' fid <- rhdf5::H5Fopen(file) -#' -#' if (species == "Co2") { -#' -#' co2_data_outloc <- rhdf5::H5Gcreate(fid, -#' paste0("/", -#' site, -#' "/dp01/ucrt/isoCo2/", -#' outname)) -#' -#' # loop through each variable in amb.data.list and write out as a dataframe -#' lapply(names(data_list), -#' function(x) { -#' rhdf5::h5writeDataset(obj = data_list[[x]], -#' h5loc = co2_data_outloc, -#' name = x, -#' DataFrameAsCompound = TRUE) -#' }) -#' -#' } else if (species == "H2o") { -#' -#' h2o_data_outloc <- rhdf5::H5Gcreate(fid, -#' paste0("/", -#' site, -#' "/dp01/ucrt/isoH2o/", -#' outname)) -#' -#' # loop through each variable in amb.data.list and write out as a dataframe. -#' lapply(names(data_list), -#' function(x) { -#' rhdf5::h5writeDataset(obj = data_list[[x]], -#' h5loc = h2o_data_outloc, -#' name = x, -#' DataFrameAsCompound = TRUE) -#' }) -#' -#' -#' } -#' -#' # close all open handles. -#' rhdf5::h5closeAll() -#' -#' } - -# nocov end diff --git a/R/isotope_conversions.R b/R/isotope_conversions.R index 914d916..f01aa60 100644 --- a/R/isotope_conversions.R +++ b/R/isotope_conversions.R @@ -3,11 +3,11 @@ # of isotope ratios and delta values. #------------------------------------------------------ #' Return heavy-to-light isotope ratio of primary standard. -#' +#' #' Returns the heavy-to-light isotope ratio of the dominant #' standard for that element. Vienna Standard Mean Ocean Water #' (VSMOW) for oxygen and hydrogen isotopes, Vienna Pee Dee -#' Belemnite (VPDB) for carbon stable isotopes. +#' Belemnite (VPDB) for carbon stable isotopes. #' #' @author Rich Fiorella \email{rfiorella@@lanl.gov} #' @@ -36,8 +36,8 @@ get_Rstd <- function(element) { } #' Convert heavy-to-light isotope ratio to delta values. -#' -#' Converts a heavy-to-light stable isotope ratio to +#' +#' Converts a heavy-to-light stable isotope ratio to #' a corresponding delta value, in per mil values. #' #' @author Rich Fiorella \email{rfiorella@@lanl.gov} @@ -64,7 +64,7 @@ R_to_delta <- function(R_values, element) { } #' Converts delta value to heavy-to-light isotope ratio -#' +#' #' Converts a delta value (in per mil) to the heavy-to-light #' isotope ratio. #' @@ -92,7 +92,7 @@ delta_to_R <- function(delta_values, element) { } #' Calculate 12C-CO2 Mole Fractions -#' +#' #' This function calculates mole fractions of 12CO2 based on the total CO2 mole #' fraction, the delta13C value of the mixture, and the assumed fraction of CO2 #' that does not correspond to 12CO2 or 13CO2 (assumed fixed at 0.00474, e.g., @@ -127,7 +127,7 @@ calculate_12CO2 <- function(total_co2, delta13c, f = 0.00474) { } #' Calculate 13C-CO2 Mole Fractions -#' +#' #' This function calculates mole fractions of 13CO2 based on the total CO2 mole #' fraction, the delta13C value of the mixture, and the assumed fraction of CO2 #' that does not correspond to 12CO2 or 13CO2 (assumed fixed at 0.00474, e.g., diff --git a/R/output_functions.R b/R/output_functions.R index 7a528df..bb1c600 100644 --- a/R/output_functions.R +++ b/R/output_functions.R @@ -42,7 +42,7 @@ setup_output_file <- function(inname, outname, site, analyte) { attrloc <- rhdf5::H5Gopen(fid, paste0("/", site)) - for (i in 1:length(tmp)) { + for (i in seq_along(tmp)) { # probably a more rapid way to do this in the future...lapply? rhdf5::h5writeAttribute(h5obj = attrloc, attr = tmp[[i]], @@ -58,7 +58,7 @@ setup_output_file <- function(inname, outname, site, analyte) { ####################################### ### FUNCTIONS THAT WORK ON ONLY CO2 ### ####################################### -#' Write carbon calibrations to file. +#' Write carbon calibrations to file #' #' @author Rich Fiorella \email{rfiorella@@lanl.gov} #' @@ -138,7 +138,7 @@ write_carbon_ambient_data <- function(outname, fid <- rhdf5::H5Fopen(outname) if (length(amb_data_list) > 0) { - for (i in 1:length(amb_data_list)) { + for (i in seq_along(amb_data_list)) { amb_data_subset <- amb_data_list[i] co2_data_outloc <- rhdf5::H5Gcreate(fid, @@ -171,7 +171,7 @@ write_carbon_ambient_data <- function(outname, ####################################### ### FUNCTIONS THAT WORK ON ONLY H2O ### ####################################### -#' Write carbon calibration parameters to file. +#' Write carbon calibration parameters to file #' #' @author Rich Fiorella \email{rfiorella@@lanl.gov} #' @@ -235,7 +235,7 @@ write_water_ambient_data <- function(outname, site, amb_data_list) { fid <- rhdf5::H5Fopen(outname) if (length(amb_data_list) > 0) { - for (i in 1:length(amb_data_list)) { + for (i in seq_along(amb_data_list)) { amb_data_subset <- amb_data_list[i] h2o_data_outloc <- rhdf5::H5Gcreate(fid, diff --git a/R/quality_control.R b/R/quality_control.R index f730438..e3f8095 100644 --- a/R/quality_control.R +++ b/R/quality_control.R @@ -1,10 +1,10 @@ # quality control - functions to validate the output data file structure #' Standardize analyte names -#' -#' Enforces standard capitalization and formatting of H2o and Co2 +#' +#' Enforces standard capitalization and formatting of H2o and Co2 #' analyte names across calibration functions. -#' +#' #' @author Rich Fiorella \email{rfiorella@@lanl.gov} #' @param analyte Co2 or H2o? #' @@ -17,9 +17,9 @@ validate_analyte <- function(analyte) { # helper function to make sure the various output functions are consistent. # check to make sure first letter of analyte is capitalized, # or capitalize if it's not (also make sure it's co2 or h2o) - if (analyte == "co2" | analyte == "h2o") { + if (analyte == "co2" || analyte == "h2o") { analyte <- paste0(toupper(substring(analyte, 1, 1)), substring(analyte, 2)) - } else if (analyte != "Co2" & analyte != "H2o") { + } else if (analyte != "Co2" && analyte != "H2o") { stop("Invalid analyte selected in setup output file.") } @@ -28,7 +28,7 @@ validate_analyte <- function(analyte) { #' Validate output file. -#' +#' #' Function ensures that the output file has the correct #' groups in it, as a check to ensure proper file structure at the #' end of the calibration routines. @@ -101,7 +101,7 @@ validate_output_file <- function(inname, outname, site, analyte) { # Diagnostic plots::: #' Make plots of carbon calibration data for debugging -#' +#' #' Makes plots of carbon calibration data regressions, primarily for #' debugging and validation purposes. #' diff --git a/R/reference_data_extraction.R b/R/reference_data_extraction.R index f9cda97..ab96f14 100644 --- a/R/reference_data_extraction.R +++ b/R/reference_data_extraction.R @@ -1,7 +1,7 @@ #' Extract only the data corresponding to validation/calibration time periods. -#' +#' #' Extracts data matching a value of "co2Low," "co2Med," or "co2High" which -#' correspond to the validation gases of known CO2, d13C that are fed to the +#' correspond to the validation gases of known CO2, d13C that are fed to the #' analyzer daily. #' #' @author Rich Fiorella \email{rfiorella@@lanl.gov} @@ -45,9 +45,9 @@ extract_carbon_cal_data <- function(data_list, } #' Extract only the data corresponding to validation/calibration time periods. -#' +#' #' Extracts data matching a value of "h2oLow," "h2oMed," or "h2oHigh" which -#' correspond to the validation gases of known d18O, d2H that are fed to the +#' correspond to the validation gases of known d18O, d2H that are fed to the #' analyzer daily. #' #' @author Rich Fiorella \email{rfiorella@@lanl.gov} diff --git a/R/reference_data_regression.R b/R/reference_data_regression.R index b9278e8..3c3f454 100644 --- a/R/reference_data_regression.R +++ b/R/reference_data_regression.R @@ -87,7 +87,7 @@ fit_carbon_regression <- function(ref_data, method, calibration_half_width, analyte = "co2", min_nobs = min_nobs) - if (method == "gainoffset" | method == "Bowling_2003") { + if (method == "gainoffset" || method == "Bowling_2003") { # calculate mole fraction (12CO2 / 13CO2) for ref gases and observed values ref_data$conc12CCO2_ref <- calculate_12CO2(ref_data$rtioMoleDryCo2Refe.mean, @@ -149,7 +149,7 @@ fit_carbon_regression <- function(ref_data, method, calibration_half_width, # okay, now run calibrations... - for (i in 1:length(date_seq)) { + for (i in seq_along(date_seq)) { start_time[i] <- as.POSIXct(paste(date_seq[i], "00:00:00.0001"), tz = "UTC", origin = "1970-01-01") @@ -185,8 +185,8 @@ fit_carbon_regression <- function(ref_data, method, calibration_half_width, abs(.data$dlta13CCo2.mean - .data$dlta13CCo2Refe.mean) < 5) - if (length(unique(cal_subset$verticalPosition)) >= 2 & - !all(is.na(cal_subset$dlta13CCo2.mean)) & + if (length(unique(cal_subset$verticalPosition)) >= 2 && + !all(is.na(cal_subset$dlta13CCo2.mean)) && !all(is.na(cal_subset$dlta13CCo2Refe.mean))) { tmpmod12c <- stats::lm(conc12CCO2_ref ~ conc12CCO2_obs, @@ -238,7 +238,7 @@ fit_carbon_regression <- function(ref_data, method, calibration_half_width, } #subset out data frame. - out <- out[1:length(start_time), ] + out <- out[seq_along(start_time), ] # output dataframe giving valid time range, slopes, intercepts, rsquared. out$timeBgn <- as.POSIXct(start_time, tz = "UTC", origin = "1970-01-01") @@ -303,7 +303,7 @@ fit_carbon_regression <- function(ref_data, method, calibration_half_width, start_time <- end_time <- vector() # okay, now run calibrations... - for (i in 1:length(date_seq)) { + for (i in seq_along(date_seq)) { start_time[i] <- as.POSIXct(paste(date_seq[i], "00:00:00.0001"), tz = "UTC", origin = "1970-01-01") @@ -328,8 +328,8 @@ fit_carbon_regression <- function(ref_data, method, calibration_half_width, abs(.data$dlta13CCo2.mean - .data$dlta13CCo2Refe.mean) < 5) - if (length(unique(cal_subset$verticalPosition)) >= 2 & - !all(is.na(cal_subset$dlta13CCo2.mean)) & + if (length(unique(cal_subset$verticalPosition)) >= 2 && + !all(is.na(cal_subset$dlta13CCo2.mean)) && !all(is.na(cal_subset$dlta13CCo2Refe.mean))) { # model to calibrate delta 13C values. @@ -385,7 +385,7 @@ fit_carbon_regression <- function(ref_data, method, calibration_half_width, } #subset out data frame. - out <- out[1:length(start_time), ] + out <- out[seq_along(start_time), ] # output dataframe giving valid time range, slopes, intercepts, rsquared. out$timeBgn <- as.POSIXct(start_time, tz = "UTC", origin = "1970-01-01") @@ -411,7 +411,7 @@ fit_carbon_regression <- function(ref_data, method, calibration_half_width, } # check to see if any out$timeBgn or end are NA - if (sum(is.na(out$timeBgn)) > 0 | sum(is.na(out$timeEnd)) > 0) { + if (sum(is.na(out$timeBgn)) > 0 || sum(is.na(out$timeEnd)) > 0) { stop("NA in calibration data frame time - how did I get here?") } @@ -520,7 +520,7 @@ fit_water_regression <- function(ref_data, # okay, now run calibrations... - for (i in 1:length(date_seq)) { + for (i in seq_along(date_seq)) { start_time[i] <- as.POSIXct(paste(date_seq[i], "00:00:00.0001"), tz = "UTC", origin = "1970-01-01") end_time[i] <- as.POSIXct(paste(date_seq[i], "23:59:59.0000"), @@ -539,8 +539,8 @@ fit_water_regression <- function(ref_data, stop("No regression data plots for water yet.") } - if (length(unique(cal_subset$verticalPosition)) >= 2 & # >= 2 standards - !all(is.na(cal_subset$dlta18OH2o.mean)) & # not all obs missing + if (length(unique(cal_subset$verticalPosition)) >= 2 && # >= 2 standards + !all(is.na(cal_subset$dlta18OH2o.mean)) && # not all obs missing !all(is.na(cal_subset$dlta18OH2oRefe.mean))) { # not all ref missing tmpmod18o <- stats::lm(dlta18OH2oRefe.mean ~ dlta18OH2o.mean, @@ -592,7 +592,7 @@ fit_water_regression <- function(ref_data, } #subset out data frame. - out <- out[1:length(start_time), ] + out <- out[seq_along(start_time), ] # output dataframe giving valid time range, slopes, intercepts, rsquared. out$timeBgn <- as.POSIXct(start_time, tz = "UTC", origin = "1970-01-01") diff --git a/R/restructure_data.R b/R/restructure_data.R index f589821..b00d223 100644 --- a/R/restructure_data.R +++ b/R/restructure_data.R @@ -33,7 +33,7 @@ ingest_data <- function(inname, analyte <- validate_analyte(analyte) backupMethod <- FALSE - + # read attributes from (first file in) inname site <- rhdf5::h5ls(inname[1], recursive = 1)[1, 2] attrs <- rhdf5::h5readAttributes(inname[1], name = paste0("/", site)) @@ -55,7 +55,7 @@ ingest_data <- function(inname, var = "isoCo2", useFasttime = TRUE)[[1]] backupMethod <- TRUE - + } } else if (packageVersion("neonUtilities") >= "2.1.1" && # nocov start packageVersion("neonUtilities") < "2.3.0") { @@ -285,7 +285,7 @@ ingest_data <- function(inname, if (nrow(ambient) > 0) { heights <- unique(ambient$verticalPosition) # not that efficient, but needed names_vector <- vector() - for (i in 1:length(heights)) { + for (i in seq_along(heights)) { names_vector[i] <- paste0("000_0", i, "0_", avg_char) } names(ambi_out) <- names_vector diff --git a/R/time_functions.R b/R/time_functions.R index 1c30e6e..9d4c980 100644 --- a/R/time_functions.R +++ b/R/time_functions.R @@ -46,9 +46,9 @@ convert_POSIXct_to_NEONhdf5_time <- function(intime) { } #' Convert NEON HDF5 file time to POSIXct -#' +#' #' Converts the date time string in NEON HDF5 files to a POSIXct object -#' for use in R. +#' for use in R. #' #' @author Rich Fiorella \email{rfiorella@@lanl.gov} #' diff --git a/R/utility_functions.R b/R/utility_functions.R index 15d25e5..cf905fd 100644 --- a/R/utility_functions.R +++ b/R/utility_functions.R @@ -6,7 +6,7 @@ #----------------------------------------------- #' List terrestrial core sites -#' +#' #' Returns a vector of four-letter NEON site codes for the #' core terrestrial sites that have TIS instrumentation. #' @@ -30,7 +30,7 @@ terrestrial_core_sites <- function() { } #' List terrestrial gradient sites -#' +#' #' Returns a vector of four-letter NEON site codes for the #' gradient terrestrial sites that have TIS instrumentation. #' @@ -58,7 +58,7 @@ terrestrial_gradient_sites <- function() { } #' List sites with water vapor isotope ratios. -#' +#' #' Returns a vector of four-letter NEON site codes for the #' terrestrial sites that have water vapor isotope ratio instrumentation. #' @@ -87,7 +87,7 @@ water_isotope_sites <- function() { #' #' Utility function to help retrieve new EC data and/or prune duplicates, #' as NEON provisions new data or re-provisions data for an existing site -#' and month. +#' and month. #' #' @author Rich Fiorella \email{rfiorella@@lanl.gov} #' @@ -180,7 +180,7 @@ manage_local_EC_archive <- function(file_dir, # okay - now loop through months and get the data files. if (!is.null(length(site_months))) { - for (j in 1:length(site_months)) { + for (j in seq_along(site_months)) { # re-query api w/ given site code and month. sitemonth_urls_json <- httr::GET( @@ -202,7 +202,7 @@ manage_local_EC_archive <- function(file_dir, dl_names <- fnames[fnames_basic] dl_urls <- furls[fnames_basic] - for (k in 1:length(dl_names)) { + for (k in seq_along(dl_names)) { if (!length(dl_names[k]) == 0) { if (!is.na(dl_names[k])) { # check to see if file exists in folder @@ -309,7 +309,7 @@ manage_local_EC_archive <- function(file_dir, file.remove(dup_candidates[h5files]) # remove files. } } else { # none are simply h5, so need to determine most recent file. - for (i in 1:length(unique(dup_yrmn))) { + for (i in seq_along(unique(dup_yrmn))) { # get times associated w/ particular duplicate. h5_times <- as.POSIXct(dup_fdiff[dup_yrmn == unique(dup_yrmn)[i]], format = "%Y%m%dT%H%M%SZ") @@ -328,4 +328,4 @@ manage_local_EC_archive <- function(file_dir, } } -} \ No newline at end of file +} diff --git a/man/write_carbon_calibration_data.Rd b/man/write_carbon_calibration_data.Rd index c165b10..fccddbd 100644 --- a/man/write_carbon_calibration_data.Rd +++ b/man/write_carbon_calibration_data.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/output_functions.R \name{write_carbon_calibration_data} \alias{write_carbon_calibration_data} -\title{Write carbon calibrations to file.} +\title{Write carbon calibrations to file} \usage{ write_carbon_calibration_data(outname, site, cal_df, method, to_file = TRUE) } @@ -26,7 +26,7 @@ regression slopes and intercepts) to the output hdf5 file. } \description{ -Write carbon calibrations to file. +Write carbon calibrations to file } \author{ Rich Fiorella \email{rfiorella@lanl.gov} diff --git a/man/write_water_calibration_data.Rd b/man/write_water_calibration_data.Rd index 50e1a98..7fe2391 100644 --- a/man/write_water_calibration_data.Rd +++ b/man/write_water_calibration_data.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/output_functions.R \name{write_water_calibration_data} \alias{write_water_calibration_data} -\title{Write carbon calibration parameters to file.} +\title{Write carbon calibration parameters to file} \usage{ write_water_calibration_data(outname, site, cal_df) } @@ -21,7 +21,7 @@ regression slopes and intercepts) to the output hdf5 file. } \description{ -Write carbon calibration parameters to file. +Write carbon calibration parameters to file } \author{ Rich Fiorella \email{rfiorella@lanl.gov}