Skip to content

Commit

Permalink
Add functions and submmodules
Browse files Browse the repository at this point in the history
  • Loading branch information
margotbrd committed Apr 22, 2021
1 parent 515fc92 commit a3224c3
Show file tree
Hide file tree
Showing 25 changed files with 912 additions and 442 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
^Meta$
^\.secrets$
^\.github$
^codecov\.yml$
42 changes: 21 additions & 21 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ License: GPL (>= 3)
Depends:
R (>= 2.10)
Imports:
config,
dplyr,
DT,
geosphere,
ggplot2,
glue,
config (>= 0.3.1),
dplyr (>= 1.0.5),
DT (>= 0.18),
geosphere (>= 1.5.10),
ggplot2 (>= 3.3.3),
glue (>= 1.4.2),
golem (>= 0.3.0),
googledrive,
leaflet,
lubridate,
magrittr,
purrr,
readr,
scales,
googledrive (>= 1.0.1),
leaflet (>= 2.0.4.1),
lubridate (>= 1.7.10),
magrittr (>= 2.0.1),
purrr (>= 0.3.4),
readr (>= 1.4.0),
scales (>= 1.1.1),
shiny (>= 1.6.0),
shinyjs,
shinymanager,
shinyWidgets,
tibble
shinyjs (>= 2.0.0),
shinymanager (>= 1.0.300),
shinyWidgets (>= 0.6.0),
tibble (>= 3.1.1)
Suggests:
knitr,
rmarkdown,
testthat,
tidyverse
knitr (>= 1.32),
rmarkdown (>= 2.7),
testthat (>= 3.0.2),
tidyverse (>= 1.3.1)
VignetteBuilder:
knitr
Config/testthat/edition: 3
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(add_info_guests_in_database)
export(count_confirmations)
export(get_count_countdown_moments)
export(get_map_wedding)
export(get_total_expenses)
Expand Down Expand Up @@ -33,6 +35,7 @@ importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_minimal)
importFrom(glue,glue)
importFrom(glue,glue_collapse)
importFrom(golem,activate_js)
importFrom(golem,add_resource_path)
importFrom(golem,bundle_resources)
Expand Down
45 changes: 45 additions & 0 deletions R/add_info_guests_in_database.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#' Add information about guests in the database
#'
#' @param info_to_add Tibble. Information to be added.
#' @param data_guests Tibble. Initial table.
#'
#' @importFrom dplyr distinct pull filter select left_join bind_rows arrange
#'
#' @return Tibble.
#' @export
#'
#' @examples
#' info_to_add_in_data_guests <- tibble::tibble(
#' name = c("David", "Margot"),
#' here_cocktail = rep("Yes", 2),
#' here_diner = rep("Yes", 2),
#' here_sunday = rep("Yes", 2),
#' special_diet = c(NA_character_, "I am vegan"),
#' menu_diner = rep("Adult", 2),
#' time_confirmation = rep("2021-04-22 09:57:12 CEST", 2)
#' )
#'
#' data(data_guests_example)
#'
#' add_info_guests_in_database(info_to_add = info_to_add_in_data_guests,
#' data_guests = data_guests_example)
add_info_guests_in_database <- function(info_to_add, data_guests) {

names_guests_to_add <- info_to_add %>%
distinct(name) %>%
pull(name)

data_guests_to_add <- data_guests %>%
filter(name %in% names_guests_to_add) %>%
select(name, type, table, announcement) %>%
left_join(info_to_add,
by = "name")

new_data_guests <- data_guests %>%
filter(!(name %in% names_guests_to_add)) %>%
bind_rows(data_guests_to_add) %>%
arrange(table)

return(new_data_guests)

}
29 changes: 29 additions & 0 deletions R/count_confirmations.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#' Count confirmations or non-confirmations
#'
#' @param filter_confirmation Character vectors. Conditions to be combined with a &
#' @param data_guests Tibble.
#'
#' @importFrom glue glue_collapse
#' @importFrom dplyr filter count pull
#'
#' @return Character.
#' @export
#'
#' @examples
#' data(data_guests_example)
#' count_confirmations(filter_confirmation = c("type == 'Teen'",
#' "(here_cocktail == 'No' |
#' here_diner == 'No' |
#' here_sunday == 'No')"),
#' data_guests = data_guests_example)
count_confirmations <- function(filter_confirmation, data_guests) {

conditions <- glue_collapse(filter_confirmation, sep = " & ")

data_guests %>%
filter(eval(parse(text = conditions))) %>%
count() %>%
pull() %>%
as.character()

}
15 changes: 14 additions & 1 deletion R/doc_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,17 @@
#' @examples
#' data("data_expenses_example")
#'
"data_expenses_example"
"data_expenses_example"

#' Example for data_guests object
#' @name data_guests_example
#' @docType data
#' @author Margot Brard \email{margot@@thinkr.fr}
#' @description This data set is a small example.
#' @format 4 rows, 40 columns. Columns are name, type, table, announcement, here_cocktail, here_diner, here_sunday, special_diet, menu_diner, time_confirmation
#' @usage
#' data("data_guests_example")
#' @examples
#' data("data_guests_example")
#'
"data_guests_example"
Loading

0 comments on commit a3224c3

Please sign in to comment.