-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b7da16
commit 3305cbf
Showing
86 changed files
with
9,728 additions
and
835 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.