Skip to content

Commit

Permalink
rev doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Edouard-Legoupil committed Nov 2, 2023
1 parent 3b7da16 commit 3305cbf
Show file tree
Hide file tree
Showing 86 changed files with 9,728 additions and 835 deletions.
12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Imports:
labelled,
plyr,
purrr,
readxl,
refugees,
riddle,
rmarkdown,
Expand All @@ -53,14 +54,13 @@ Suggests:
knitr,
openxlsx,
testthat
Remotes:
unhcr-dataviz/unhcrdown,
unhcr-dataviz/unhcrthemes,
edouard-legoupil/unhcrshiny,
edouard-legoupil/kobocruncher,
edouard-legoupil/riddle
VignetteBuilder:
knitr
Remotes:
edouard-legoupil/kobocruncher,
edouard-legoupil/riddle,
edouard-legoupil/unhcrshiny,
unhcr-dataviz/unhcrthemes
Config/fusen/version: 0.5.2
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Expand Down
8 changes: 5 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Generated by roxygen2: do not edit by hand

export(compass_table)
export(fct_check_map)
export(fct_compass_table)
export(fct_get_all_variable_names)
export(fct_kobo_dummy)
export(fct_plot_indic_donut)
export(fct_plot_rbm_sdg)
export(fct_re_map)
export(fct_var_dummy)
export(fct_var_mapping)
export(impact_2_2)
export(inter_drinkingwater)
export(inter_electricity)
export(inter_healthcare)
export(inter_shelter)
export(kobo_dummy)
export(plot_rbm_sdg)
export(run_app)
export(var_dummy)
import(golem)
Expand Down
2 changes: 1 addition & 1 deletion R/compass_table.R → R/fct_compass_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#' # ),
#' # ridl = params$ridl,
#' # publish = params$publish )
compass_table <- function(country ,
fct_compass_table <- function(country ,
operation,
year ,
population_type,
Expand Down
16 changes: 8 additions & 8 deletions R/kobo_dummy.R → R/fct_kobo_dummy.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# WARNING - Generated by {fusen} from dev/utilities.Rmd: do not edit by hand

#' kobo_dummy
#' fct_kobo_dummy
#'
#' @description Automatically produce an dummy dataset in line with the structure
#' of an XlsForm
Expand Down Expand Up @@ -34,14 +34,14 @@
#' @export
#' @examples
#' form <- system.file("RMSCAPI.xlsx", package = "IndicatorCalc")
#' datalist <- kobo_dummy(form,
#' datalist <- fct_kobo_dummy(form,
#' n = 384,
#' file = NULL)
#'
#' ## Save this to use it for testing the package...
#'
#' openxlsx::write.xlsx(datalist, here::here("inst", "demo_data.xlsx"))
kobo_dummy <- function(form,
fct_kobo_dummy <- function(form,
n = 384,
file){

Expand Down Expand Up @@ -87,7 +87,7 @@ kobo_dummy <- function(form,
))
names(main)[1] <- "_index"

## then apply var_dummy interactively...
## then apply fct_var_dummy interactively...
for(i in (1:nrow(conf)) ) {
# i <- 6
cat(paste0(i, "-", conf[i, c("type")], "-", conf[i, c("name")], "\n"))
Expand All @@ -104,7 +104,7 @@ kobo_dummy <- function(form,
this.type <- "text"
}

main <- var_dummy(
main <- fct_var_dummy(
frame = main,
name = this.name,
type = this.type,
Expand All @@ -120,7 +120,7 @@ kobo_dummy <- function(form,
# type,
# list_opt$list_opt ,
# constraint ,
# var_dummy)
# fct_var_dummy)

## TODO -- apply the relevance statement...
## define when the variable should exist based on other elements
Expand Down Expand Up @@ -188,7 +188,7 @@ kobo_dummy <- function(form,
## Apply now `_index`
## TODO -- check if we have a `repeat_count` to apply limitation..

## then apply var_dummy interactively...
## then apply fct_var_dummy interactively...
for(i in (1:nrow(confrep)) ) {
# i <- 6
cat(paste0(i, " in repeat -", rep, " ///", confrep[i, c("type")], "-", confrep[i, c("name")], "\n"))
Expand All @@ -205,7 +205,7 @@ kobo_dummy <- function(form,
this.type <- "text"
}

repframe <- var_dummy(
repframe <- fct_var_dummy(
frame = repframe,
name = this.name,
type = this.type,
Expand Down
4 changes: 2 additions & 2 deletions R/plot_rbm_sdg.R → R/fct_plot_rbm_sdg.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#' @return a ggplot2 object
#' @export
#' @examples
#' plot_rbm_sdg( country = "BRA",
#' fct_plot_rbm_sdg( country = "BRA",
#' rbm = "impact2_2",
#' years = c(2000, 2022)) +
#' unhcrthemes::theme_unhcr(font_size = 10)
plot_rbm_sdg <- function( country = "BRA",
fct_plot_rbm_sdg <- function( country = "BRA",
rbm = "outcome16_2",
years = c(2000, 2022)) {
require(ggplot2)
Expand Down
182 changes: 182 additions & 0 deletions R/fct_var_dummy.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# WARNING - Generated by {fusen} from dev/utilities.Rmd: do not edit by hand

#' fct_var_dummy
#'
#' Append to an existing dataframe new Generate the variable based on 1. type, 2. constraint and 3.relevance
#'
#' @param frame dataframe object where new dummy varaible will be created...
#' @param name name of the variable to be created
#' @param type type of the variable to be created in line with xlsform -
#' one of the following 6 options:
#' "select_one", "select_multiple", "text", "integer", "numeric", "date"
#'
#' "start ", "end", "calculate", "geopoint","acknowledge",
#' "begin_group", "end_group", "begin_repeat", "end_repeat" , "note"
#'
#' @param list_opt a vector with all possible values for select_one and select_multiple
#' - can be null
#' @param constraint specific constraint - used for for numeric or integer
## @param seed random seed
#'
#' @return dataframe
#'
#' @importFrom withr with_seed
#' @importFrom dplyr mutate n tibble rename
#' @importFrom stats rlnorm
#' @importFrom tidyr unnest
#'
#' @noRd
#'
#' @export
#' @examples
#'
#' ## let's initiate a dataframe with an index of n r records
#' n <- 384
#' frame <- dplyr::tibble(
#' index = paste0( "ID-",
#' purrr::as_vector(
#' purrr::map(n, sample(LETTERS, 4)) |>
#' purrr::map(paste0, collapse = "")),
#' "-",
#' formatC(1:n, width = nchar(n) + 1, flag = "0")
#' ))
#'
#' ## test inject select_one
#' frame <- fct_var_dummy(
#' frame = frame,
#' name = "testselect_one",
#' type = "select_one",
#' list_opt = c("alpha", "beta", "delta"),
#' constraint = NULL
#' )
#' ## test inject select_multiple in main
#' frame <- fct_var_dummy(
#' frame = frame,
#' name = "testselect_multiple",
#' type = "select_multiple",
#' list_opt = c("alpha", "beta", "delta"),
#' constraint = NULL
#' )
#'
#' ## test inject text
#' frame <- fct_var_dummy(
#' frame = frame,
#' name = "testtext",
#' type = "text",
#' list_opt = NULL,
#' constraint = NULL
#' )
#'
#'
#' ## test inject numeric
#' frame <- fct_var_dummy(
#' frame = frame,
#' name = "testnumeric",
#' type = "numeric",
#' list_opt = NULL,
#' constraint = NULL
#' )
#'
#' ## test inject date
#' frame <- fct_var_dummy(
#' frame = frame,
#' name = "testdate",
#' type = "date",
#' list_opt = NULL,
#' constraint = NULL
#' )
#'
#' ## Preview out out
#' knitr::kable(head(frame, 5))
fct_var_dummy <- function( frame,
name,
type,
list_opt,
constraint #,
# seed = 1976
) {
## number of records to be generated depends on the initial frame..
n <- nrow(frame)
#withr::with_seed(seed = seed)
# withr::with_seed(
# seed = seed,
# suppressWarnings(

# no content ###########
if( type %in% c("begin_group", "end_group", "begin_repeat", "end_repeat" , "note" )) {
res <- dplyr::tibble(
thisvar = NA)
names(res)[1] <- name
frame <- cbind(frame,res)
}


## acknowledge ###########
if( type %in% c("acknowledge")) {
res <- dplyr::tibble(
thisvar = sample(c(0,1), n, replace = TRUE))
names(res)[1] <- name
frame <- cbind(frame,res)
}


## select one ###########
if( type %in% c("select_one") ) {
res <- dplyr::tibble( thisvar = sample(c(list_opt), n, replace = TRUE) )
## Now rename the variable
names(res)[1] <- name
frame <- cbind(frame,res)
}

## select multiple ###########
if( type %in% c("select_multiple")) {
for (modality in list_opt) {
res <- dplyr::tibble(
thisvar = sample(c(0,1), n, replace = TRUE))
names(res)[1] <- paste0(name, "_",modality )
frame <- cbind(frame,res)
}
}

## stext ###########
if( type %in% c("text")) {
res <- dplyr::tibble(
thisvar = paste0( "FreeText_",
purrr::as_vector(
purrr::map(n, sample(LETTERS, 6)) |>
purrr::map(paste0, collapse = "")),
"-",
formatC(1:n, width = nchar(n) + 1, flag = "0")
))
## Now rename the variable
names(res)[1] <- name
frame <- cbind(frame,res)
}

## numeric ###########
if( type %in% c("numeric", "integer", "calculate", "geopoint")) {
## TODO extract elements from constraint to define num1 an num2
num1 <- 18
num2 <- 95

res <- dplyr::tibble(
thisvar = sample(num1:num2, n, replace = TRUE))
## Now rename the variable
names(res)[1] <- name
frame <- cbind(frame,res)
}

## date ###########
if( type %in% c("date", "start ", "end")) {
res <- dplyr::tibble(
thisvar = Sys.time() - abs(rnorm(n, 0, sd = 2) * 365 * 24 * 3600))
## Now rename the variable
names(res)[1] <- name
frame <- cbind(frame,res)
}

# )
# )

return(frame)
}
28 changes: 28 additions & 0 deletions R/fct_var_mapping.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# WARNING - Generated by {fusen} from dev/utilities.Rmd: do not edit by hand

#' fct_var_mapping
#'
#' Create a diff to identify the mapping between expected variables / modalities and
#' what is has been configured in a specific xlsform
#'
#' @param xlsformpath path to the xlsform
#' @param mappingfile_out path to file to out the mapping
#'
#' @return a list with the best mapping...
#'
#' @export
#' @examples
#'
#' form <- system.file("RMSCAPI.xlsx", package = "IndicatorCalc")
#' #fct_var_mapping(xlsformpath = form)
fct_var_mapping <- function(xlsformpath){

IndicMap <- readxl::read_excel( system.file("IndicMap.xlsx", package = "IndicatorCalc"))
dico <- kobocruncher::kobo_dico(xlsformpath)

## Map variable


## Map modalities

}
7 changes: 6 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ knitr::opts_chunk$set(
)
```

# {IndicatorCalc}
# {IndicatorCalc} <img src="man/figures/logo.png" align="right" height="139" alt="" />

<!-- badges: start -->
[![:name status badge](https://unhcrverse.r-universe.dev/badges/:name)](https://unhcrverse.r-universe.dev/)
Expand All @@ -29,6 +29,7 @@ The package is designed to work based on dataset standard backup format exported
Each calculation is implemented as a function with in-built check to identify whether the expected variables and modalities are within the dataset and a `mapper` to transform the data in the expected format in case of divergence of data structure between what was collected and what is expected. You can check each [function reference](/reference/index.html) to see in details all documented calculations


Please check the [tutorial here](https://edouard-legoupil.github.io/IndicatorCalc/tutorial/index.html)

## Usage

Expand Down Expand Up @@ -68,4 +69,8 @@ The easiest way to do that is by calling `usethis::edit_r_environ()` and adding



## Contributing

Contributions to the packages are welcome. Please, follow the [code of conduct](CODE_OF_CONDUCT.html).

If you encounter a bug or have idea for a new feature or check, please fill a ticket on [github](https://github.com/edouard-legoupil/IndicatorCalc/issues/new/choose).
Loading

0 comments on commit 3305cbf

Please sign in to comment.