Skip to content

Commit

Permalink
lintr cleanup for 0.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rfiorella committed Dec 29, 2024
1 parent d898349 commit 6cd46c7
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 272 deletions.
20 changes: 10 additions & 10 deletions R/calibrate_ambient_carbon_gainoffset.R
Original file line number Diff line number Diff line change
@@ -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(...)
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions R/calibrate_ambient_carbon_linreg.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
10 changes: 5 additions & 5 deletions R/calibrate_ambient_water_isotopes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
}
Expand All @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions R/calibrate_carbon.R
Original file line number Diff line number Diff line change
Expand Up @@ -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')")
}

Expand Down
197 changes: 0 additions & 197 deletions R/excised.R

This file was deleted.

14 changes: 7 additions & 7 deletions R/isotope_conversions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}
#'
Expand Down Expand Up @@ -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}
Expand All @@ -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.
#'
Expand Down Expand Up @@ -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.,
Expand Down Expand Up @@ -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.,
Expand Down
Loading

0 comments on commit 6cd46c7

Please sign in to comment.