Skip to content

Commit fb01804

Browse files
committed
Added correct template for v1.0 preparation and call to correct file in scripts
1 parent 05d3b34 commit fb01804

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+445
-628
lines changed

.Rbuildignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
^mocaredd\.Rproj$
22
^\.Rproj\.user$
3-
3+
^\tests\workbooks\.xlsx$
44

55
^checks$
66
^_pkgdown\.yml$

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ vignettes/*.png
55
vignettes/*.csv
66
inst/extdata/example1_conf.xlsx
77
inst/extdata/example2_conf.xlsx
8+
tests/workbooks
89

910
# History files
1011
.Rhistory

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: mocaredd
22
Title: Monte Carlo Simulation for REDD+ uncertainty analysis
3-
Version: 0.0.0.9000
3+
Version: 0.3.0
44
Authors@R: c(
55
person("Gael", "Sola", , "gaso.ella@gmail.com", role = c("aut", "cre"),
66
comment = c(ORCID = "YOUR-ORCID-ID")),

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@ importFrom(ggplot2,scale_y_discrete)
3636
importFrom(ggplot2,theme)
3737
importFrom(ggplot2,theme_classic)
3838
importFrom(ggplot2,theme_minimal)
39-
importFrom(magrittr,"%>%")
4039
importFrom(rlang,":=")
4140
importFrom(rlang,.data)

R/fct_arithmetic_mean.R

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,19 @@
1414
#' transition, REDD+ activity or emission reductions level.
1515
#'
1616
#' @importFrom rlang .data
17-
#' @importFrom magrittr %>%
1817
#'
1918
#' @examples
2019
#' library(readxl)
2120
#' library(dplyr)
2221
#' library(mocaredd)
2322
#'
24-
#' cs <- read_xlsx(
25-
#' system.file("extdata/example1.xlsx", package = "mocaredd"),
26-
#' sheet = "c_stocks",
27-
#' na = "NA"
28-
#' )
29-
#' ad <- read_xlsx(
30-
#' system.file("extdata/example1.xlsx", package = "mocaredd"),
31-
#' sheet = "AD_lu_transitions",
32-
#' na = "NA"
33-
#' )
34-
#' usr <- read_xlsx(
35-
#' system.file("extdata/example1.xlsx", package = "mocaredd"),
36-
#' sheet = "user_inputs",
37-
#' na = "NA"
38-
#' )
23+
#' path <- system.file("extdata/example1-4pools.xlsx", package = "mocaredd")
3924
#'
40-
#' time <- read_xlsx(
41-
#' path = system.file("extdata/example1.xlsx", package = "mocaredd"),
42-
#' sheet = "time_periods",
43-
#' na = "NA"
44-
#' )
25+
#' cs <- read_xlsx(path = path, sheet = "c_stocks", na = "NA")
26+
#' ad <- read_xlsx(path = path, sheet = "AD_lu_transitions", na = "NA")
27+
#' usr <- read_xlsx(path = path, sheet = "user_inputs", na = "NA")
28+
#'
29+
#' time <- read_xlsx(path = path, sheet = "time_periods", na = "NA")
4530
#'
4631
#' #ad_clean <- ad |> dplyr::filter(!is.na(trans_area) | !is.na(trans_pdf_a))
4732
#' #cs_clean <- cs |> dplyr::filter(!is.na(c_value) | !is.na(c_pdf_a))

R/fct_calc_res.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#' @return A tibble with simulation results per category if ID column: estimated mean,
1515
#' percentage uncertainty, margin of error, lower and upper bound of confidence interval.
1616
#'
17-
#' @importFrom magrittr %>%
1817
#' @importFrom rlang .data
1918
#'
2019
#' @examples
@@ -31,18 +30,18 @@ fct_calc_res <- function(
3130
col_id <- rlang::enquo(.id)
3231
col_sim <- rlang::enquo(.sim)
3332

34-
.data %>%
35-
dplyr::group_by(!!col_id) %>%
33+
.data |>
34+
dplyr::group_by(!!col_id) |>
3635
dplyr::summarise(
3736
E = round(stats::median(!!col_sim)),
3837
E_cilower = round(stats::quantile(!!col_sim, .ci_alpha/2)),
3938
E_ciupper = round(stats::quantile(!!col_sim, 1 - .ci_alpha/2)),
4039
.groups = "drop"
41-
) %>%
40+
) |>
4241
dplyr::mutate(
4342
E_ME = round((.data$E_ciupper - .data$E_cilower) / 2),
4443
E_U = round(.data$E_ME / .data$E * 100),
45-
) %>%
44+
) |>
4645
dplyr::select(!!col_id, "E", "E_U", "E_ME", "E_cilower", "E_ciupper")
4746

4847
}

R/fct_check_data.R

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,10 @@
1515
#' library(mocaredd)
1616
#' library(readxl)
1717
#'
18-
#' cs <- read_xlsx(
19-
#' path = system.file("extdata/example1.xlsx", package = "mocaredd"),
20-
#' sheet = "c_stocks",
21-
#' na = "NA"
22-
#' )
23-
#' ad <- read_xlsx(
24-
#' path = system.file("extdata/example1.xlsx", package = "mocaredd"),
25-
#' sheet = "AD_lu_transitions",
26-
#' na = "NA"
27-
#' )
18+
#' path <- system.file("extdata/example1-4pools.xlsx", package = "mocaredd")
19+
#'
20+
#' cs <- read_xlsx(path = path, sheet = "c_stocks", na = "NA")
21+
#' ad <- read_xlsx(path = path, sheet = "AD_lu_transitions", na = "NA")
2822
#'
2923
#'.init <- init <- list(
3024
#' c_pools = c("AGB", "BGB", "RS", "DW", "LI", "SOC", "ALL", "DG_ratio"),

R/fct_check_data2.R

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,17 @@
1616
#' if FALSE.
1717
#'
1818
#' @importFrom rlang .data
19-
#' @importFrom magrittr %>%
2019
#'
2120
#' @examples
2221
#' library(mocaredd)
2322
#' library(readxl)
2423
#'
25-
#' cs <- read_xlsx(
26-
#' path = system.file("extdata/example1.xlsx", package = "mocaredd"),
27-
#' sheet = "c_stocks",
28-
#' na = "NA"
29-
#' )
30-
#' ad <- read_xlsx(
31-
#' path = system.file("extdata/example1.xlsx", package = "mocaredd"),
32-
#' sheet = "AD_lu_transitions",
33-
#' na = "NA"
34-
#' )
35-
#' usr <- read_xlsx(
36-
#' path = system.file("extdata/example1.xlsx", package = "mocaredd"),
37-
#' sheet = "user_inputs",
38-
#' na = "NA"
39-
#' )
40-
#' time <- read_xlsx(
41-
#' path = system.file("extdata/example1.xlsx", package = "mocaredd"),
42-
#' sheet = "time_periods",
43-
#' na = "NA"
44-
#' )
24+
#' path <- system.file("extdata/example1-4pools.xlsx", package = "mocaredd")
25+
#'
26+
#' cs <- read_xlsx(path = path, sheet = "c_stocks", na = "NA")
27+
#' ad <- read_xlsx(path = path, sheet = "AD_lu_transitions", na = "NA")
28+
#' usr <- read_xlsx(path = path, sheet = "user_inputs", na = "NA")
29+
#' time <- read_xlsx(path = path, sheet = "time_periods", na = "NA")
4530
#'
4631
#' app_checklist <- list(
4732
#' xlsx_tabs = c("user_inputs", "time_periods", "AD_lu_transitions", "c_stocks"),
@@ -273,7 +258,7 @@ fct_check_data2 <- function(.usr, .time, .ad, .cs, .checklist){
273258
## - Period matching exactly between tables
274259
tmp$match_period_ad_ok <- all(sort(unique(.ad$trans_period)) == sort(unique(.time$period_no)))
275260

276-
cs_period <- .cs %>% dplyr::filter(.data$c_period != "ALL")
261+
cs_period <- .cs |> dplyr::filter(.data$c_period != "ALL")
277262
if (nrow(cs_period) > 0) {
278263
tmp$match_period_cs_ok <- all(sort(unique(.cs$c_period)) == sort(unique(.time$period_no)))
279264
} else {
@@ -287,8 +272,8 @@ fct_check_data2 <- function(.usr, .time, .ad, .cs, .checklist){
287272
tmp$match_lu_ok <- all(lu_ad %in% lu_cs)
288273

289274
## - At least one ref and one monitoring period
290-
nb_ref <- .time %>% dplyr::filter(stringr::str_detect(.data$period_type, pattern = "REF|REF[0-9]"))
291-
nb_mon <- .time %>% dplyr::filter(stringr::str_detect(.data$period_type, pattern = "MON|MON[0-9]"))
275+
nb_ref <- .time |> dplyr::filter(stringr::str_detect(.data$period_type, pattern = "REF|REF[0-9]"))
276+
nb_mon <- .time |> dplyr::filter(stringr::str_detect(.data$period_type, pattern = "MON|MON[0-9]"))
292277

293278
tmp$match_ref_ok <- nrow(nb_ref) > 0
294279
tmp$match_mon_ok <- nrow(nb_mon) > 0

R/fct_check_pool.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
#' library(readxl)
2424
#' library(dplyr)
2525
#'
26-
#' cs <- read_xlsx(
27-
#' path = system.file("extdata/example1.xlsx", package = "mocaredd"),
28-
#' sheet = "c_stocks",
29-
#' na = "NA"
30-
#' )
26+
#' path <- system.file("extdata/example1-4pools.xlsx", package = "mocaredd")
27+
#'
28+
#' cs <- read_xlsx(path = path, sheet = "c_stocks", na = "NA")
29+
#'
3130
#' c_lu <- cs |> filter(lu_id == "ev_wet_closed")
3231
#'
3332
#' fct_check_pool(.c_lu = c_lu, .c_unit = "C", .c_fraction = NA)

R/fct_combine_mcs_E.R

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,17 @@
1313
#' transition, REDD+ activity or emission reductions level.
1414
#'
1515
#' @importFrom rlang .data
16-
#' @importFrom magrittr %>%
1716
#'
1817
#' @examples
1918
#' library(readxl)
2019
#' library(dplyr)
2120
#' library(mocaredd)
2221
#'
23-
#' cs <- read_xlsx(
24-
#' system.file("extdata/example1.xlsx", package = "mocaredd"),
25-
#' sheet = "c_stocks",
26-
#' na = "NA"
27-
#' )
28-
#' ad <- read_xlsx(
29-
#' system.file("extdata/example1.xlsx", package = "mocaredd"),
30-
#' sheet = "AD_lu_transitions",
31-
#' na = "NA"
32-
#' )
33-
#' usr <- read_xlsx(
34-
#' system.file("extdata/example1.xlsx", package = "mocaredd"),
35-
#' sheet = "user_inputs",
36-
#' na = "NA"
37-
#' )
22+
#' path <- system.file("extdata/example1-4pools.xlsx", package = "mocaredd")
23+
#'
24+
#' cs <- read_xlsx(path = path, sheet = "c_stocks", na = "NA")
25+
#' ad <- read_xlsx(path = path, sheet = "AD_lu_transitions", na = "NA")
26+
#' usr <- read_xlsx(path = path, sheet = "user_inputs", na = "NA")
3827
#'
3928
#' cs_clean <- cs |> filter(!is.na(c_value) | !is.na(c_pdf_a))
4029
#'
@@ -80,7 +69,7 @@ fct_combine_mcs_E <- function(.ad, .cs, .usr){
8069
# print(x)
8170
## !!
8271

83-
ad_x <- .ad %>% dplyr::filter(.data$trans_id == x)
72+
ad_x <- .ad |> dplyr::filter(.data$trans_id == x)
8473
redd_x <- ad_x$redd_activity
8574

8675
## AD - Activity Data
@@ -134,9 +123,9 @@ fct_combine_mcs_E <- function(.ad, .cs, .usr){
134123
# dg_pool <- stringr::str_split(.usr$dg_pool, pattern = ",") |> purrr::map(stringr::str_trim) |> unlist()
135124
# dg_pool_i <- paste0(dg_pool, "_i")
136125
#
137-
# combi <- combi %>%
138-
# dplyr::rowwise() %>%
139-
# dplyr::mutate(C_all_f = .data$DG_ratio_f * sum(!!!rlang::syms(dg_pool_i))) %>%
126+
# combi <- combi |>
127+
# dplyr::rowwise() |>
128+
# dplyr::mutate(C_all_f = .data$DG_ratio_f * sum(!!!rlang::syms(dg_pool_i))) |>
140129
# dplyr::ungroup()
141130
#
142131
# ## If degradation has unaffected pools, we identify them by difference and add them to final C stock
@@ -149,9 +138,9 @@ fct_combine_mcs_E <- function(.ad, .cs, .usr){
149138
# dg_expool <- paste0(setdiff(c_pools, dg_pool), "_i")
150139
#
151140
# if (length(dg_expool) > 0) {
152-
# combi <- combi %>%
153-
# dplyr::rowwise() %>%
154-
# dplyr::mutate(C_all_f = .data$C_all_f + sum(!!!rlang::syms(dg_expool))) %>%
141+
# combi <- combi |>
142+
# dplyr::rowwise() |>
143+
# dplyr::mutate(C_all_f = .data$C_all_f + sum(!!!rlang::syms(dg_expool))) |>
155144
# dplyr::ungroup()
156145
# }
157146
# }
@@ -164,11 +153,11 @@ fct_combine_mcs_E <- function(.ad, .cs, .usr){
164153
## END LOOP
165154

166155
## Re-arrange columns and add EF and E (emissions at transition level)
167-
tt <- mcs_trans %>%
156+
mcs_trans |>
168157
dplyr::mutate(
169158
EF = round((.data$C_all_i - .data$C_all_f) * 44/12, 0),
170159
E_sim = round(.data$AD * .data$EF, 0)
171-
) %>%
160+
) |>
172161
# dplyr::mutate(dplyr::across(c(.data$E_sim, .data$AD, .data$EF, .data$C_all_i, .data$C_all_f))) |>
173162
dplyr::select(
174163
"sim_no", "redd_activity", time_period = "trans_period", "trans_id",

0 commit comments

Comments
 (0)