Skip to content

Commit

Permalink
minor fn revision
Browse files Browse the repository at this point in the history
  • Loading branch information
dustintharper committed Feb 22, 2024
1 parent 4d38938 commit 4bcbcdf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 12 additions & 10 deletions R/age_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ age_index <- function(load_proxy = load_foram,
cust_steps){

prox_in <- load_proxy[[1]]
obs_type <- load_proxy[[2]]
if(!is.null(load_proxy[[2]])){
obs_type <- load_proxy[[2]]
}

if (age_units == "kyr"){
if(age_units == "kyr"){
prox_in$age = prox_in$age
} else if (age_units == "Myr"){
} else if(age_units == "Myr"){
prox_in$age = prox_in$age*1e3
step_int = step_int*1e3
if(!is.null(cust_steps)){
Expand All @@ -52,19 +54,19 @@ age_index <- function(load_proxy = load_foram,

ages_prox = unique(prox_in$age)

if (step_type == "every"){
if(step_type == "every"){
prox_in_ai = transform(prox_in, ai = as.numeric(factor(age*-1)))

} else if (step_type == "regular"){
if (step_int > 0 & step_int < ((max(ages_prox) - min(ages_prox))/2)){
} else if(step_type == "regular"){
if(step_int > 0 & step_int < ((max(ages_prox) - min(ages_prox))/2)){
prox_in_ai = transform(prox_in, ai = as.numeric(1 + floor((max(prox_in$age) - prox_in$age) / step_int)))
ages_prox = seq(from = max(ages_prox), to = min(ages_prox), by = -1*step_int) - 0.5*step_int
} else{
stop("Must specify positive value less than half the length of the total time interval for 'step_int' in function arguments if regular time step type is selected")
}

} else if (step_type =="both"){
if (step_int > 0 & step_int < ((max(ages_prox) - min(ages_prox))/2)){
} else if(step_type =="both"){
if(step_int > 0 & step_int < ((max(ages_prox) - min(ages_prox))/2)){
ai = c(1:length(prox_in$age))
ages_prox = unique(sort(append(prox_in$age,(seq(from = max(ages_prox), to = min(ages_prox), by = -1*step_int) - 0.5*step_int)), decreasing = TRUE))
for (i in seq_along(prox_in$age)){
Expand All @@ -76,12 +78,12 @@ age_index <- function(load_proxy = load_foram,
}

} else if (step_type =="custom"){
if (is.null(cust_steps)){
if(is.null(cust_steps)){
stop("Must include a vector of ages for 'cust_steps' argument if 'custom' is specified for 'step_type'.")
}
ai = c(1:length(prox_in$age))
ages_prox = sort(cust_steps, decreasing = TRUE)
for (i in seq_along(prox_in$age)){
for(i in seq_along(prox_in$age)){
ai[i] <- which(abs(ages_prox - prox_in$age[i]) == min(abs(ages_prox - prox_in$age[i])))
}
prox_in_ai = transform(prox_in, ai = sort(as.numeric(ai)))
Expand Down
4 changes: 1 addition & 3 deletions R/load_foram.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#' This function allows you to load, QC and format foram data to use in subsequent 'BPER' functions.
#' Function checks which data are present and whether measurement uncertainties are included.
#' If ages or uncertainties are not included the function stops. Function flags 'incomplete'
#' data object - i.e., missing Mg/Ca, or missing d18O, or missing d11B - but proceeds. Function also writes
#' "priors_in_foram.R" to parent directory which needs to be modified before 'priors_foram' function is used.
#' If no modifications to priors are needed, this can be turned off using 'load.priors' argument. Dependencies: 'readxl'.
#' data object - i.e., missing Mg/Ca, or missing d18O, or missing d11B - but proceeds. Dependencies: 'readxl'.
#'
#' @param foram_data User inputs an 8 column R data object and assigns it to 'foram_data' in arguments. Object columns
#' should be organized as: age, d11B, d11B2s, d11Bspec, Mg/Ca, Mg/Ca2s, d18O, d18O2s. The order matters. Current
Expand Down

0 comments on commit 4bcbcdf

Please sign in to comment.