Skip to content

Commit 75950d6

Browse files
committed
Minor Changes for CRAN recommendations and website update
1 parent ab59514 commit 75950d6

40 files changed

+301
-653
lines changed

DESCRIPTION

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ Author: Alexander Klug [aut, cre, cph],
2121
Seda Bekar [ctb]
2222
Dirk Zeuss [aut]
2323
Maintainer: Alexander Klug <[email protected]>
24-
Description: Climate Modelling package providing an automated climate modelling workflow.
24+
Description: An automated and streamlined workflow for predictive climate
25+
mapping using climate station data. Works within an environment
26+
the user provides a destined path to (otherwise it's `tempdir()`).
27+
Quick and relatively easy creation of resilient and reproduceable
28+
climate models, predictions and climate maps, shortening the
29+
usually long and complicated work of predictive modelling.
30+
For more information, please find the provided URL.
2531
License: GPL (>= 3)
2632
Encoding: UTF-8
2733
LazyData: true
@@ -53,5 +59,5 @@ Suggests:
5359
VignetteBuilder: knitr
5460
RoxygenNote: 7.3.2
5561
Config/testthat/edition: 3
56-
URL: https://github.com/envima/climodr
62+
URL: https://envima.github.io/climodr/
5763
BugReports: https://github.com/envima/climodr/issues

R/Autocorrelation.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#' @export autocorr
1818
#'
1919
#' @examples
20-
#' \dontrun{
20+
#' \donttest{
2121
#' # Test data for autocorrelation after running fin.csv
2222
#' autocorr(method = "monthly",
2323
#' resp = 5,
@@ -160,7 +160,7 @@ autocorr <- function(
160160
)
161161
} # end corlist-loop
162162

163-
print(
163+
message(
164164
paste0(
165165
"Calculated autocorrelations for these sensors [",
166166
sensor_names,

R/Environment.R

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
#' @export envi.create
1616
#'
1717
#' @examples
18-
#' \dontrun{
18+
#' \donttest{
1919
#' # create climodr environment and allow terra-functions to use 70% of RAM
20-
#' envi.create("C:/user/climodr_user/project_directory",
21-
#' memfrac = 0.7)
20+
#' envi.create(proj_path = tempdir(),
21+
#' memfrac = 0.7)
2222
#' }
2323
#'
24-
envi.create <- function(proj_path,
24+
envi.create <- function(proj_path = tempdir(),
2525
memfrac = NULL,
2626
...) {
2727
projectDirList = c("input/dep/",
@@ -108,7 +108,7 @@ envi.create <- function(proj_path,
108108
terra::terraOptions(tempdir = envrmt$path_tmp,
109109
memfrac = memfrac)
110110
}
111-
print(
111+
message(
112112
paste0(
113113
"Succesfully created an environment in ",
114114
proj_path,
@@ -140,8 +140,8 @@ envi.create <- function(proj_path,
140140
#' }
141141
#'
142142
clim.sample <- function(envrmt = .GlobalEnv$envrmt){
143-
print("Loading example data for the climodr example..")
144-
print(environment())
143+
message("Loading example data for the climodr example..")
144+
message(environment())
145145
# Input dep folder
146146
data("res_area", envir = environment())
147147
data("plot_description", envir = environment())
@@ -151,7 +151,7 @@ clim.sample <- function(envrmt = .GlobalEnv$envrmt){
151151
terra::writeRaster(res_area, file.path(envrmt$path_dep, "res_area.tif"), overwrite = TRUE)
152152
write.csv(plot_description, file.path(envrmt$path_dep, "plot_description.csv"))
153153

154-
print(paste0("Saved climodr example dependency files to {", envrmt$path_dep, "}."))
154+
message(paste0("Saved climodr example dependency files to {", envrmt$path_dep, "}."))
155155
rm(list = setdiff(ls(), "envrmt"))
156156
gc()
157157

@@ -164,7 +164,7 @@ clim.sample <- function(envrmt = .GlobalEnv$envrmt){
164164
terra::writeRaster(sch_201707, file.path(envrmt$path_raster, "sch_201707.tif"), overwrite = TRUE)
165165
terra::writeRaster(sch_dgm, file.path(envrmt$path_raster, "sch_dgm.tif"), overwrite = TRUE)
166166

167-
print(paste0("Saved climodr example raster files to {", envrmt$path_raster, "}."))
167+
message(paste0("Saved climodr example raster files to {", envrmt$path_raster, "}."))
168168
rm(list = setdiff(ls(), "envrmt"))
169169
gc()
170170

@@ -177,7 +177,7 @@ clim.sample <- function(envrmt = .GlobalEnv$envrmt){
177177
eval(call("write.csv", as.name(i), file.path(envrmt$path_tabular, paste0(i, ".csv")), row.names = FALSE))
178178
}
179179

180-
print(paste0("Saved climodr example tabular files to {", envrmt$path_tabular, "}."))
180+
message(paste0("Saved climodr example tabular files to {", envrmt$path_tabular, "}."))
181181
rm(list = setdiff(ls(), "envrmt"))
182182
gc()
183183

@@ -187,11 +187,11 @@ clim.sample <- function(envrmt = .GlobalEnv$envrmt){
187187

188188
terra::writeVector(ext_vignette, file.path(envrmt$path_vector, "ext_vignette.gpkg"), overwrite = TRUE)
189189

190-
print(paste0("Saved climodr example vector files to {", envrmt$path_vector, "}."))
190+
message(paste0("Saved climodr example vector files to {", envrmt$path_vector, "}."))
191191
rm(list = setdiff(ls(), "envrmt"))
192192
gc()
193193

194194
# Talk to the User
195-
print("Done loading all the example files. You are ready to continue.")
195+
message("Done loading all the example files. You are ready to continue.")
196196
}
197197

R/Modelling.R

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#' @export calc.model
4646
#'
4747
#' @examples
48-
#' \dontrun{
48+
#' \donttest{
4949
#' # Create 48 different models (12 months x 4 classifiers) for every month in 2017
5050
#' calc.model(method = "monthly",
5151
#' timespan = c(2017),
@@ -98,7 +98,7 @@ calc.model <- function(
9898
# Optional: activate for faster computing
9999
if (doParallel == TRUE){
100100
# talk to the user
101-
print("Starting parallelization.")
101+
message("Starting parallelization.")
102102

103103
cr <- parallel::detectCores()
104104
cl <- parallel::makeCluster(cr * 0.75)
@@ -122,14 +122,14 @@ calc.model <- function(
122122
months <- unique(data_y$month)
123123

124124
# talk to the user
125-
print(paste0("Training models for ", y, ". Year-Nr.: ", which(timespan == y), "/", length(timespan)))
125+
message(paste0("Training models for ", y, ". Year-Nr.: ", which(timespan == y), "/", length(timespan)))
126126

127127
# Loop for monthly models ----------------------------------------- Month --- #
128128
for (m in months) try ({
129129
data_m <- data_y[c(which(data_y$month == m)), ]
130130

131131
# talk to the user
132-
print(paste0("Training monthly models for ", y,". Month-Nr.: ", m))
132+
message(paste0("Training monthly models for ", y,". Month-Nr.: ", m))
133133

134134
# Loop for the climate sensors --------------------------------- Climresp --- #
135135
for (s in climresp) try({
@@ -146,7 +146,7 @@ calc.model <- function(
146146

147147
if(autocorrelation == "TRUE"){
148148
# talk to the user
149-
print("Use autocorellation data for filtering..")
149+
message("Use autocorellation data for filtering..")
150150
data <- data_m[stats::complete.cases(data_m), ]
151151
delect <-
152152
utils::read.csv(
@@ -188,7 +188,7 @@ calc.model <- function(
188188
spacevar = "plot"
189189
)
190190
# talk to the user
191-
print(
191+
message(
192192
paste0(
193193
"Run with spatial folds for cross validation. Fold-Nr.: ",
194194
which(f == dofolds), "/", length(dofolds)
@@ -201,7 +201,7 @@ calc.model <- function(
201201
timevar = "datetime"
202202
)
203203
# talk to the user
204-
print(
204+
message(
205205
paste0(
206206
"Run with temporal folds for cross validation. Fold-Nr.: ",
207207
which(f == dofolds), "/", length(dofolds)
@@ -215,7 +215,7 @@ calc.model <- function(
215215
spacevar = "plot"
216216
)
217217
# talk to the user
218-
print(
218+
message(
219219
paste0(
220220
"Run with spatio-temporal folds for cross validation. Fold-Nr.: ",
221221
which(f == dofolds), "/", length(dofolds)
@@ -240,7 +240,7 @@ calc.model <- function(
240240
resps <- trainingDat[ ,s]
241241

242242
# talk to the user
243-
print(
243+
message(
244244
paste0(
245245
"Calculate models for sensor: ",
246246
sensor_names[which(s == climresp)])
@@ -295,27 +295,27 @@ calc.model <- function(
295295
savePredictions = TRUE)
296296
modclass <-"gbm"
297297
# talk to the user
298-
print(paste0("Next model: Stochastic Gradient Boosting. ", i, "/", length(classifier)))
298+
message(paste0("Next model: Stochastic Gradient Boosting. ", i, "/", length(classifier)))
299299
}
300300
if (method == "lm"){
301301
tuneLength <- 10
302302
modclass <- "lim"
303303
# talk to the user
304-
print(paste0("Next model: Linear Regression. ", i, "/", length(classifier)))
304+
message(paste0("Next model: Linear Regression. ", i, "/", length(classifier)))
305305
}
306306
if (method == "rf"){
307307
tuneLength <- 1
308308
tuneGrid <- expand.grid(mtry = 2)
309309
modclass <- "raf"
310310
# talk to the user
311-
print(paste0("Next model: Random Forest. ", i, "/", length(classifier)))
311+
message(paste0("Next model: Random Forest. ", i, "/", length(classifier)))
312312
}
313313
if (method == "pls"){
314314
# preds <- data.frame(scale(preds))
315315
tuneLength <- 10
316316
modclass <- "pls"
317317
# talk to the user
318-
print(paste0("Next model: Partial-Least-Squares. ", i, "/", length(classifier)))
318+
message(paste0("Next model: Partial-Least-Squares. ", i, "/", length(classifier)))
319319
}
320320
if (method == "nnet"){
321321
tuneLength <- 1
@@ -324,11 +324,11 @@ calc.model <- function(
324324
)
325325
modclass <- "nnt"
326326
# talk to the user
327-
print(paste0("Next model: Neural Networks. ", i, "/", length(classifier)))
327+
message(paste0("Next model: Neural Networks. ", i, "/", length(classifier)))
328328
}
329329

330330
# talk to the user
331-
print("Computing model...")
331+
message("Computing model...")
332332

333333
# calculate model
334334
ffsmodel <- CAST::ffs(
@@ -405,7 +405,7 @@ calc.model <- function(
405405
}) # end timespan loop [y]
406406

407407
#talk to the user
408-
print("Done! Saving evaluation data frame.")
408+
message("Done! Saving evaluation data frame.")
409409

410410
# save total loop analytics for eval
411411
saveRDS(df_total, file.path(envrmt$path_statistics, paste0(mnote, "_mod_eval_df.rds")));
@@ -414,7 +414,7 @@ calc.model <- function(
414414
# stop paralellization, if it was activated
415415
if (doParallel == TRUE){
416416
#talk to the user
417-
print("Ending parallelization.")
417+
message("Ending parallelization.")
418418
parallel::stopCluster(cl)
419419
}
420420

R/Plotting.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#' @importFrom grDevices adjustcolor colorRampPalette dev.off png
2121
#'
2222
#' @examples
23-
#' \dontrun{
23+
#' \donttest{
2424
#' # Create a Temperature Map from the vignette model
2525
#' climplot(mnote = "vignette",
2626
#' sensor = "Ta_200",
@@ -46,7 +46,7 @@ climplot <- function(
4646

4747
for (s in 1:length(sensor)){
4848
preds <- all_preds[which(grepl(all_preds, pattern = paste0(mnote, "_", sensor[s])))]
49-
print(paste0("Creating maps for sensor [", sensor[s], "]."))
49+
message(paste0("Creating maps for sensor [", sensor[s], "]."))
5050

5151
for (i in 1:length(preds)){
5252
filename <- gsub("_prediction.tif.*", "", preds[i])

R/PreProcessing.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ prep.csv <- function(envrmt = .GlobalEnv$envrmt,
108108
row.names = FALSE
109109
)
110110
}
111-
print(
111+
message(
112112
paste0(
113113
"Removed NAs from ",
114114
number_of_csvs,
@@ -620,7 +620,7 @@ spat.csv <- function(envrmt = .GlobalEnv$envrmt,
620620
#' @export fin.csv
621621
#'
622622
#' @examples
623-
#' \dontrun{
623+
#' \donttest{
624624
#' csv_fin <- fin.csv(method = "monthly",
625625
#' save_output = TRUE)
626626
#' head(csv_fin)

R/Prediction.R

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#' @export climpred
1616
#'
1717
#' @examples
18-
#' \dontrun{
18+
#' \donttest{
1919
#' climpred(method = "monthly",
2020
#' mnote = "normal",
2121
#' AOA = TRUE)
@@ -103,7 +103,7 @@ climpred <- function(
103103
)
104104
)
105105

106-
print(
106+
message(
107107
paste0(
108108
"Making ",
109109
mod_df[i, ]$sensor,
@@ -134,12 +134,13 @@ climpred <- function(
134134
)
135135

136136
if (isTRUE(AOA)) try({
137-
oldw <- getOption("warn") # old settings
138-
options(warn = -1) # turn off warnings
139-
140-
aoa <- CAST::aoa(
141-
newdata = raster,
142-
model = mod)
137+
suppressWarnings(
138+
suppressMessages(
139+
aoa <- CAST::aoa(
140+
newdata = raster,
141+
model = mod)
142+
)
143+
)
143144
names(aoa$AOA) <- paste0(modname, "_aoa")
144145
terra::writeRaster(
145146
aoa$AOA,
@@ -152,8 +153,6 @@ climpred <- function(
152153
),
153154
overwrite = TRUE
154155
)
155-
156-
options(warn = oldw) # return old warning settings
157156
})
158157
} # end i loop
159158

0 commit comments

Comments
 (0)