From eca601e1cb26d2be14eee57ba06f307ed31470a1 Mon Sep 17 00:00:00 2001 From: Alan Butler Date: Fri, 27 Oct 2023 12:08:34 -0600 Subject: [PATCH] removed all 1:length(..) #121 --- R/get_prism_annual.R | 6 +++--- R/get_prism_dailys.R | 2 +- R/get_prism_monthlys.R | 6 +++--- R/get_prism_normals.R | 2 +- R/pd_get_md.R | 2 +- R/utility_functions.R | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/R/get_prism_annual.R b/R/get_prism_annual.R index dc037fd..6643929 100644 --- a/R/get_prism_annual.R +++ b/R/get_prism_annual.R @@ -100,7 +100,7 @@ get_prism_annual <- function(type, years, keepZip = TRUE, ### Handle post 1980 data if(length(uris_post81) > 0){ - for(i in 1:length(uris_post81)){ + for(i in seq_along(uris_post81)) { prism_webservice(uris_post81[i],keepZip) setTxtProgressBar(download_pb, i) } @@ -112,7 +112,7 @@ get_prism_annual <- function(type, years, keepZip = TRUE, if (length(uris_pre81) > 0) { pre_files <-c() - for(j in 1:length(uris_pre81)){ + for(j in seq_along(uris_pre81)){ tmp <- prism_webservice( uris_pre81[j], keepZip, @@ -133,7 +133,7 @@ get_prism_annual <- function(type, years, keepZip = TRUE, pre_files <- unlist(strsplit(pre_files,"\\.")) pre_files <- pre_files[seq(1,length(pre_files),by =2)] - for (k in 1:length(pre_files)) { + for (k in seq_along(pre_files)) { if (keep_pre81_months) { # keep the annual data to_split <- gsub(pattern = "_all", replacement = "", x = pre_files[k]) diff --git a/R/get_prism_dailys.R b/R/get_prism_dailys.R index 3e88f0b..3f7795f 100644 --- a/R/get_prism_dailys.R +++ b/R/get_prism_dailys.R @@ -114,7 +114,7 @@ get_prism_dailys <- function(type, minDate = NULL, maxDate = NULL, download_pb <- txtProgressBar(min = 0, max = max(length(uris), 1), style = 3) if(length(uris) > 0){ - for(i in 1:length(uris)){ + for(i in seq_along(uris)){ prism_webservice(uri = uris[i],keepZip) setTxtProgressBar(download_pb, i) } diff --git a/R/get_prism_monthlys.R b/R/get_prism_monthlys.R index 85b6449..538cc9b 100644 --- a/R/get_prism_monthlys.R +++ b/R/get_prism_monthlys.R @@ -72,7 +72,7 @@ get_prism_monthlys <- function(type, years, mon = 1:12, keepZip = TRUE, ### Handle post 1981 data if(length(uris_post81) > 0){ - for(i in 1:length(uris_post81)){ + for(i in seq_along(uris_post81)){ prism_webservice(uris_post81[i],keepZip) setTxtProgressBar(download_pb, i) } @@ -84,7 +84,7 @@ get_prism_monthlys <- function(type, years, mon = 1:12, keepZip = TRUE, if (length(uris_pre81) > 0) { pre_files <- c() - for (j in 1:length(uris_pre81)) { + for (j in seq_along(uris_pre81)) { tmp <- prism_webservice( uris_pre81[j], keepZip, @@ -103,7 +103,7 @@ get_prism_monthlys <- function(type, years, mon = 1:12, keepZip = TRUE, pre_files <- unlist(strsplit(pre_files,"\\.")) pre_files <- pre_files[seq(1, length(pre_files), by = 2)] - for (k in 1:length(pre_files)) { + for (k in seq_along(pre_files)) { yr <- regmatches(pre_files[k], regexpr('[0-9]{4}', pre_files[k])) if (keep_pre81_months) { diff --git a/R/get_prism_normals.R b/R/get_prism_normals.R index 24f4dcd..683faa4 100644 --- a/R/get_prism_normals.R +++ b/R/get_prism_normals.R @@ -66,7 +66,7 @@ get_prism_normals <- function(type, resolution, mon = NULL, annual = FALSE, mpb <- txtProgressBar(min = 0, max =length(uris), style = 3) - for(i in 1:length(uris)){ + for(i in seq_along(uris)){ prism_webservice(uris[i],keepZip) setTxtProgressBar(mpb, i) diff --git a/R/pd_get_md.R b/R/pd_get_md.R index 140bf3b..2113083 100644 --- a/R/pd_get_md.R +++ b/R/pd_get_md.R @@ -57,7 +57,7 @@ pd_get_md <- function(pd) { if (length(final_txt_full) == 0) { stop("No files exist to obtain metadata from.") } - out <- lapply(1:length(final_txt_full), function(i) { + out <- lapply(seq_along(final_txt_full), function(i) { readin <- tryCatch( utils::read.delim( final_txt_full[i], diff --git a/R/utility_functions.R b/R/utility_functions.R index f4b5ad0..7840fee 100644 --- a/R/utility_functions.R +++ b/R/utility_functions.R @@ -12,7 +12,7 @@ mon_to_string <- function(month) { out <- vector() - for(i in 1:length(month)){ + for(i in seq_along(month)){ if(month[i] < 1 || month[i] > 12) { stop("Please enter a valid numeric month") } @@ -156,7 +156,7 @@ process_zip <- function(pfile, name) fstrip <- unlist(lapply(fstrip, function(x) return(x[1]))) unames <- unique(fstrip) unames <- unames[unames %in% name] - for(j in 1:length(unames)){ + for(j in seq_along(unames)){ newdir <- file.path(prism_get_dl_dir(), unames[j]) tryCatch( dir.create(newdir),