diff --git a/NAMESPACE b/NAMESPACE index 21100fc..9f6ac92 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,4 +2,7 @@ export("%>%") export(map_data) +export(individuals_by) +export(initiative_by) +export(replace_other) importFrom(magrittr,"%>%") diff --git a/R/individuals_by.R b/R/individuals_by.R new file mode 100644 index 0000000..db41dd4 --- /dev/null +++ b/R/individuals_by.R @@ -0,0 +1,197 @@ +#' "individuals_by" +#' +#' @description individuals_by function creates a force-directed network visualization using the forceNetwork function from the networkD3 package. +#' +#' @param individual_data The data frame containing the individual-level data. By default, it assumes a data frame called `individuals`. +#' @param ind_id The variable/column in the `individual_data` data frame that represents the individual identifier. By default, it assumes a column named "nom". +#' @param group The variable/column in the `individual_data` data frame that represents the grouping variable. It is used to assign colors to the nodes in the visualization. If not provided, the visualization will not group the nodes. +#' @param group_other is a string representing the name of the column in the "individual_data" data block that contains additional group information for each individual. +#' @param group_other_name is a string representing a custom name for the "group_other" column to display in the plot. +#' @param font_size numeric font size in pixels for the node text labels.By default, it is set to 7. +#' @param height numeric height for the network graph's frame area in pixels. +#' @param width numeric width for the network graph's frame area in pixels. +#' @param colour_scale character string specifying the categorical colour scale for the nodes. See \code{https://github.com/d3/d3/blob/master/API.md#ordinal-scales}. +#' @param font_family font family for the node text labels. +#' @param link_distance numeric or character string. Either numberic fixed distance between the links in pixels (actually arbitrary relative to the diagram's size). Or a JavaScript function, possibly to weight by Value. For example: linkDistance = JS("function(d){return d.value * 10}"). +#' @param link_width numeric or character string. Can be a numeric fixed width in pixels (arbitrary relative to the diagram's size). Or a JavaScript function, possibly to weight by Value. The default is linkWidth = JS("function(d) { return Math.sqrt(d.value); }"). +#' @param radius_calculation character string. A javascript mathematical expression, to weight the radius by Nodesize. The default value is radiusCalculation = JS("Math.sqrt(d.nodesize)+6"). +#' @param charge numeric value indicating either the strength of the node repulsion (negative value) or attraction (positive value). +#' @param link_colour character vector specifying the colour(s) you want the link lines to be. Multiple formats supported (e.g. hexadecimal). +#' @param opacity numeric value of the proportion opaque you would like the graph elements to be. +#' @param zoom logical value to enable (TRUE) or disable (FALSE) zooming. +#' @param arrows logical value to enable directional link arrows. +#' @param bounded logical value to enable (TRUE) or disable (FALSE) the bounding box limiting the graph's extent. See \code{http://bl.ocks.org/mbostock/1129492}. +#' @param display_labels is a numeric value representing the number of characters of the label to display on each node. +#' @param click_action character string with a JavaScript expression to evaluate when a node is clicked. +#' +#' @return Returns a network graph object +#' @export +#' +#' @examples # TODO +individuals_by <- function(individual_data = individuals, ind_id = nom, group = NULL, group_other = NULL, group_other_name = NULL, + font_size = 7, height = NULL, width = NULL, colour_scale = JS("d3.scaleOrdinal(d3.schemeCategory20);"), + font_family = "serif", link_distance = 50, link_width = JS("function(d) { return Math.sqrt(d.value); }"), + radius_calculation = "4*Math.sqrt(d.nodesize)+2", charge = -30, + link_colour = "#666", opacity = 0.6, zoom = FALSE, arrows = FALSE, + bounded = FALSE, display_labels = 0, click_action = NULL){ + + # if (!is.null(filter_var)){ + # individual_data <- individual_data %>% + # filter(.data[[filter_var]] %in% filter_vals) + # } + + # ind data + ind <- individual_data %>% + dplyr::mutate(id_ind = gsub("^.*?/","", {{ ind_id }})) + + # put this if statement elsewhere - own function + # replace "other" columns with what the user selected: + if (group %in% c("pays", "activite_prof")){ + if (group == "pays") { + group_other_name = "autre_pays" + } else if (group %in% c("activite_prof")){ + group_other_name = "autre" + } + ind <- replace_other(data = ind, + group = group, + group_other_name = group_other_name, + RAS = TRUE) + } + + ind <- replace_other(data = ind, + group = "institutions_associees", + group_other_name = "autre") + ind <- replace_other(data = ind, + group = "initiatives_associees", + group_other_name = "autre_initiative") + + # for prep fun + ind.init_inst <- ind %>% + # Create a variable giving the institution + tidyr::pivot_longer(cols = starts_with("institutions_associees/"), names_to = "id_inst") %>% + dplyr::mutate(id_inst = gsub("^.*?/", "", id_inst)) %>% + dplyr::mutate(id_inst = gsub("institutions_associees/","", id_inst)) %>% + dplyr::filter(value == 1) %>% + dplyr::select(!value) %>% + + # Create a variable giving the initiative + tidyr::pivot_longer(cols = starts_with("initiatives_associees/"), names_to = "id_init") %>% + dplyr::mutate(id_init = gsub("^.*?/","", id_init)) %>% + dplyr::mutate(id_init = gsub("initiatives_associees/","", id_init)) %>% + dplyr::filter(value == 1) %>% + dplyr::select(!value)%>% + + # combine the initiative and institution column into one + tidyr::pivot_longer(cols = c(id_inst,id_init), + names_to = "inst_init_type", values_to = "id_inst_init") %>% + dplyr::mutate(inst_init_type = case_when( + inst_init_type == 'id_inst' ~ "Institution", + inst_init_type == 'id_init' ~ "Initiative")) + + # Split the data `ind.init_inst` to just Institutions + inst.ind <- ind.init_inst %>% + dplyr::filter(inst_init_type == "Institution") %>% + dplyr::distinct(id_inst_init) %>% + dplyr::rename(id_inst = id_inst_init) + + # Split the data `ind.init_inst` to just Initatives + init.ind <- ind.init_inst %>% + dplyr::filter(inst_init_type == "Initiative") %>% + dplyr::distinct(id_inst_init) %>% + dplyr::rename(id_init = id_inst_init) # rename "id_init" by "id_inst_init" + + # Creating the node data: bind our three data sets together + # (individual, inst.ind, init.ind) + # Add a column to state if it is individual, institution, or initiative data + nodes_init_by <- bind_rows ( + "Individu(e)" = rename(ind, id=id_ind), + "Institution" = rename(inst.ind, id=id_inst), + "Initiative" = rename(init.ind, id=id_init), + .id = "type") %>% + # add a weight + tidyr::mutate(type_weight = case_when( + type == 'Individu(e)' ~ 1, + type == 'Institution' ~ 2, + type == 'Initiative' ~ 3)) + + # Create notes and links data + # if there is a group variable, then create a "group_type" variable + if (!is.null(group)){ + nodes_init_by <- nodes_init_by %>% + dplyr::mutate(group_type = case_when( + type == 'Individu(e)' ~ .data[[group]], + type == 'Institution' ~ "Institution", + type == 'Initiative' ~ "Initiative")) %>% + dplyr::mutate(id_index = row_number() - 1) %>% + dplyr::select(c("id", "id_index", "type_weight", "group_type")) + } else { + nodes_init_by <- nodes_init_by %>% + dplyr::mutate(id_index = row_number()-1) %>% + dplyr::select(c("id", "id_index", "type", "type_weight")) + } + + # Merge the id_index column into the ind.init_inst data by initiative + # set this id_index column to be "target" + links_init_by <- ind.init_inst %>% + dplyr::left_join(y=rename(select(nodes_init_by, id, id_index), + target=id_index), + by = c("id_inst_init"="id")) + + # Now merge in the id_index column into the ind.init_inst data by individual + # set this id_index column to be "source" + links_init_by <- links_init_by %>% + dplyr::left_join(y=rename(select(nodes_init_by, id, id_index), + source=id_index), + by = c("id_ind"="id")) + + # Add a numerical weight to whether it is institution or initiative + links_init_by <- links_init_by %>% + dplyr::mutate(inst_init_type_weight = case_when( + inst_init_type == "Institution" ~ '2', + inst_init_type == "Initiative" ~ '1')) %>% + dplyr::select(c(target, source, inst_init_type, inst_init_type_weight)) + + if (display_labels) { + display_labels = 1 + } else { + display_labels = 0 + } + + if (is.null(group)){ + networkD3::forceNetwork(Links = links_init_by, + Nodes = nodes_init_by, + Source = "source", + Target = "target", + NodeID = "id", + Nodesize = "type_weight", + Group = "type", + legend = TRUE, + fontSize = font_size, + height = height, width = width, + colourScale = colour_scale, fontFamily = font_family, + linkDistance = link_distance, linkWidth = link_width, + radiusCalculation = radius_calculation, charge = charge, + linkColour = link_colour, opacity = opacity, zoom = zoom, + arrows = arrows, bounded = bounded, opacityNoHover = display_labels, + clickAction = click_action) + } + else { + networkD3::forceNetwork(Links = links_init_by, + Nodes = nodes_init_by, + Source = "source", + Target = "target", + NodeID = "id", + Nodesize = "type_weight", + Group = "group_type", + legend = TRUE, + fontSize = font_size, + height = height, width = width, + colourScale = colour_scale, fontFamily = font_family, + linkDistance = link_distance, linkWidth = link_width, + radiusCalculation = radius_calculation, charge = charge, + linkColour = link_colour, opacity = opacity, zoom = zoom, + arrows = arrows, bounded = bounded, opacityNoHover = display_labels, + clickAction = click_action) + } +} + diff --git a/R/initiative_by.R b/R/initiative_by.R index d1cb623..1c18d1f 100644 --- a/R/initiative_by.R +++ b/R/initiative_by.R @@ -4,67 +4,74 @@ #' explain what it does - #' #' @param initiative_data a data frame object containing the initiative data -#' @param by -#' @param filter_var -#' @param filter_vals +#' @param by the values around which nodes are formed +#' @param filter_var filtered variable +#' @param filter_vals values associated to the filter #' @param node_size character string specifying the a column in the `initiative_data` data frame with some value to vary the node radius's with. See also \code{radiusCalculation}. #' @param group character string specifying the group of each node in the `initiative_data` data frame. -#' @param font_size -#' @param height -#' @param width -#' @param colour_scale -#' @param font_family -#' @param link_distance -#' @param link_width -#' @param radius_calculation -#' @param charge -#' @param link_colour -#' @param opacity -#' @param zoom -#' @param arrows -#' @param bounded +#' @param font_size numeric font size in pixels for the node text labels. +#' @param height numeric height for the network graph's frame area in pixels. +#' @param width numeric width for the network graph's frame area in pixels. +#' @param colour_scale character string specifying the categorical colour scale for the nodes. See https://github.com/d3/d3/blob/master/API.md#ordinal-scales. +#' @param font_family font family for the node text labels. +#' @param link_distance numeric or character string. Either numberic fixed distance between the links in pixels (actually arbitrary relative to the diagram's size). Or a JavaScript function, possibly to weight by Value. For example: linkDistance = JS("function(d){return d.value * 10}"). +#' @param link_width numeric or character string. Can be a numeric fixed width in pixels (arbitrary relative to the diagram's size). Or a JavaScript function, possibly to weight by Value. The default is linkWidth = JS("function(d) { return Math.sqrt(d.value); }"). +#' @param radius_calculation character string. A javascript mathematical expression, to weight the radius by Nodesize. The default value is radiusCalculation = JS("Math.sqrt(d.nodesize)+6"). +#' @param charge numeric value indicating either the strength of the node repulsion (negative value) or attraction (positive value). +#' @param link_colour character vector specifying the colour(s) you want the link lines to be. Multiple formats supported (e.g. hexadecimal). +#' @param opacity numeric value of the proportion opaque you would like the graph elements to be. +#' @param zoom logical value to enable (TRUE) or disable (FALSE) zooming. +#' @param arrows logical value to enable directional link arrows. +#' @param bounded logical value to enable (TRUE) or disable (FALSE) the bounding box limiting the graph's extent. See http://bl.ocks.org/mbostock/1129492. #' @param display_labels -#' @param click_action +#' @param click_action character string with a JavaScript expression to evaluate when a node is clicked. #' #' @return Returns a network graph object #' #' @examples # todo -initiative_by <- function(initiative_data, by = "pays", filter_var = NULL, filter_vals = NULL, +initiative_by <- function(initiative_data, by = "pays", sep = ".", filter_var = NULL, filter_vals = NULL, node_size = c("type", "age"), group = NULL, font_size = 7, height = NULL, width = NULL, colour_scale = JS("d3.scaleOrdinal(d3.schemeCategory20);"), font_family = "serif", link_distance = 50, link_width = JS("function(d) { return Math.sqrt(d.value); }"), radius_calculation = "4*Math.sqrt(d.nodesize)+2", charge = -30, link_colour = "#666", opacity = 0.6, zoom = FALSE, arrows = FALSE, bounded = FALSE, display_labels = 0, click_action = NULL){ + # characteristics of nodes node_size <- match.arg(node_size) # if (!is.null(filter_var)){ # initiative_data <- initiative_data %>% # filter(.data[[filter_var]] %in% filter_vals) # } + # Replacement of the boxes in the "initiative_name" column with the associated values in the "other_initiative" column" init <- replace_other(data = initiative_data, group = "nom_initiative", group_other = "autre_initiative", group_other_name = "autre_initiative") - init <- rename(init, id_init = nom_initiative) + # Rename the column "initiative_name" by id_init + init <- dplyr::rename(init, id_init = nom_initiative) + # creation of the CCRP column for CCRP donors if (!is.null(group)){ init <- init %>% dplyr::mutate(CCRP = case_when( - `donateur/ccrp_mcknight_foundation` == 1 ~ group, + paste0("donateur", sep, "ccrp_mcknight_foundation") == 1 ~ group, TRUE ~ "autre")) - } + } + # Creation of age column if (node_size == "age"){ init <- init %>% dplyr::mutate(age = 2023 - date_creation) } + # pivoting and filtering of data init.by <- init %>% # pivot_wider(names_from = Pays_Autre_nom, values_from = Pays_Autre, names_prefix = "Pays_") %>% # select(!c(Pays_)) %>% - tidyr::pivot_longer(cols = starts_with(paste0(by, "/")), names_to = "id_by") %>% + tidyr::pivot_longer(cols = starts_with(paste0(by, sep)), names_to = "id_by")%>% dplyr::mutate(id_by = gsub("^.*?/","", id_by)) %>% - dplyr::mutate(id_by = gsub(paste0(by, "/"), "", id_by)) %>% + dplyr::mutate(id_by = gsub(paste0(by, sep), "", id_by))%>% dplyr::filter(value == 1) - + # Elimination of repetitions. by.init <- init.by %>% distinct(id_by) # Create notes and links data ------------------------------------------------ by_var <- by + print("A") nodes_init_by <- bind_rows ( "Initiative" = rename(init, id = id_init), @@ -78,30 +85,30 @@ initiative_by <- function(initiative_data, by = "pays", filter_var = NULL, filte type == 'Initiative' ~ 2)) } else { nodes_init_by <- nodes_init_by %>% - mutate(type_weight = case_when( + dplyr::mutate(type_weight = case_when( type == by ~ 0, type == 'Initiative' ~ age)) } if (!is.null(group)){ nodes_init_by <- nodes_init_by %>% - mutate(group_type = case_when( + dplyr::mutate(group_type = case_when( type == by ~ by, type == 'Initiative' ~ .data[[group]])) %>% # replace CCRP with {{ group }}? - mutate(id_index = row_number()-1) %>% + dplyr::mutate(id_index = row_number()-1) %>% select(id, id_index, type, type_weight, group_type) %>% - mutate(group_type = replace_na(group_type, "Unknown")) + dplyr::mutate(group_type = replace_na(group_type, "Unknown")) } else { nodes_init_by <- nodes_init_by %>% - mutate(id_index = row_number()-1) %>% + dplyr::mutate(id_index = row_number()-1) %>% select(id, id_index, type, type_weight) } links_init_by <- init.by %>% - left_join(y=rename(select(nodes_init_by, id, id_index), - target=id_index), + left_join(y=dplyr::rename(select(nodes_init_by, id, id_index), + target=id_index), by = c("id_by"="id")) %>% - left_join(y=rename(select(nodes_init_by, id, id_index), - source=id_index), + left_join(y=dplyr::rename(select(nodes_init_by, id, id_index), + source=id_index), by = c("id_init"="id")) %>% select(c(target, source)) diff --git a/R/replace_other.R b/R/replace_other.R new file mode 100644 index 0000000..052a676 --- /dev/null +++ b/R/replace_other.R @@ -0,0 +1,52 @@ +#' "replace_other" +#' +#' @description This function replaces a specific group in a data frame with another group. +#' +#' @param data The data frame in which the replacement will be performed. By default, it assumes a data frame called `individuals`. +#' @param group The name of the group variable to be replaced. This parameter is required. +#' @param group_other The name of the replacement group variable. It is constructed by appending the prefix "autre_" to the original group name. For example, if `group` is "pays", then `group_other` becomes "autre_pays". +#' @param group_other_name The specific value within the `group` variable that should be replaced. When this value is encountered in the `group` variable, it will be replaced with the corresponding value from `group_other`. This parameter is required. +#' @param RAS A logical value indicating whether the replacement should be performed with "RAS" when the `group_other_name` is encountered. If `RAS` is set to `TRUE`, the replacement will be "RAS"; otherwise, it will be the corresponding value from `group_other`. By default, it is set to `FALSE`. +#' +#' +#' @note The `mutate` function is used to create a new column in the data frame named `group_var`, which replaces the values based on the provided conditions. When `RAS` is set to `TRUE`, it checks if the value in the `group` variable is equal to `group_other_name`. If it is, the corresponding value from `group_other` is assigned to `group_var`. Additionally, if the value in the `group` variable is `NA` (missing), it is replaced with "RAS". If `RAS` is set to `FALSE`, the replacement is performed without using "RAS". +#' +#' @return Returns data +#' @export +#' +#' @examples # TODO + + +replace_other <- function(data = individuals, group = NULL, group_other = paste0("autre_", group), group_other_name = NULL, RAS = FALSE){ + group_var <- group + # if (group_other == "autre_pays"){ + # data <- data %>% + # mutate(!!group_var := case_when( + # .data[[group]] == group_other_name ~ case_when( + # is.na(.data[[group_other]]) ~ "autre", + # TRUE ~ .data[[group_other]]), + # is.na(.data[[group]]) ~ 'RAS', + # TRUE ~ .data[[group]])) + # } else { + if (RAS){ + data <- data %>% + + #create a new column in the data frame named "group_var", which replaces the values based on the provided conditions. + mutate(!!group_var := case_when( + .data[[group]] == group_other_name ~ .data[[group_other]], + is.na(.data[[group]]) ~ "RAS", + TRUE ~ .data[[group]])) + } else { + data <- data %>% + mutate(!!group_var := case_when( + .data[[group]] == group_other_name ~ .data[[group_other]], + TRUE ~ .data[[group]])) + } + # } + return(data) +} + +# when +# variable (group) == "autre" ~ (variable group col name), +# is.na(group) , +# TRUE ~ groip \ No newline at end of file diff --git a/man/individuals_by.Rd b/man/individuals_by.Rd new file mode 100644 index 0000000..d66070d --- /dev/null +++ b/man/individuals_by.Rd @@ -0,0 +1,82 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/individuals_by.R +\name{individuals_by} +\alias{individuals_by} +\title{"individuals_by"} +\usage{ +individuals_by( + individual_data = individuals, + ind_id = nom, + group = NULL, + group_other = NULL, + group_other_name = NULL, + font_size = 7, + height = NULL, + width = NULL, + colour_scale = JS("d3.scaleOrdinal(d3.schemeCategory20);"), + font_family = "serif", + link_distance = 50, + link_width = JS("function(d) { return Math.sqrt(d.value); }"), + radius_calculation = "4*Math.sqrt(d.nodesize)+2", + charge = -30, + link_colour = "#666", + opacity = 0.6, + zoom = FALSE, + arrows = FALSE, + bounded = FALSE, + display_labels = 0, + click_action = NULL +) +} +\arguments{ +\item{individual_data}{The data frame containing the individual-level data. By default, it assumes a data frame called \code{individuals}.} + +\item{ind_id}{The variable/column in the \code{individual_data} data frame that represents the individual identifier. By default, it assumes a column named "nom".} + +\item{group}{The variable/column in the \code{individual_data} data frame that represents the grouping variable. It is used to assign colors to the nodes in the visualization. If not provided, the visualization will not group the nodes.} + +\item{group_other}{is a string representing the name of the column in the "individual_data" data block that contains additional group information for each individual.} + +\item{group_other_name}{is a string representing a custom name for the "group_other" column to display in the plot.} + +\item{font_size}{numeric font size in pixels for the node text labels.By default, it is set to 7.} + +\item{height}{numeric height for the network graph's frame area in pixels.} + +\item{width}{numeric width for the network graph's frame area in pixels.} + +\item{colour_scale}{character string specifying the categorical colour scale for the nodes. See \code{https://github.com/d3/d3/blob/master/API.md#ordinal-scales}.} + +\item{font_family}{font family for the node text labels.} + +\item{link_distance}{numeric or character string. Either numberic fixed distance between the links in pixels (actually arbitrary relative to the diagram's size). Or a JavaScript function, possibly to weight by Value. For example: linkDistance = JS("function(d){return d.value * 10}").} + +\item{link_width}{numeric or character string. Can be a numeric fixed width in pixels (arbitrary relative to the diagram's size). Or a JavaScript function, possibly to weight by Value. The default is linkWidth = JS("function(d) { return Math.sqrt(d.value); }").} + +\item{radius_calculation}{character string. A javascript mathematical expression, to weight the radius by Nodesize. The default value is radiusCalculation = JS("Math.sqrt(d.nodesize)+6").} + +\item{charge}{numeric value indicating either the strength of the node repulsion (negative value) or attraction (positive value).} + +\item{link_colour}{character vector specifying the colour(s) you want the link lines to be. Multiple formats supported (e.g. hexadecimal).} + +\item{opacity}{numeric value of the proportion opaque you would like the graph elements to be.} + +\item{zoom}{logical value to enable (TRUE) or disable (FALSE) zooming.} + +\item{arrows}{logical value to enable directional link arrows.} + +\item{bounded}{logical value to enable (TRUE) or disable (FALSE) the bounding box limiting the graph's extent. See \code{http://bl.ocks.org/mbostock/1129492}.} + +\item{display_labels}{is a numeric value representing the number of characters of the label to display on each node.} + +\item{click_action}{character string with a JavaScript expression to evaluate when a node is clicked.} +} +\value{ +Returns a network graph object +} +\description{ +individuals_by function creates a force-directed network visualization using the forceNetwork function from the networkD3 package. +} +\examples{ +# TODO +} diff --git a/man/initiative_by.Rd b/man/initiative_by.Rd index 52a998f..5e034aa 100644 --- a/man/initiative_by.Rd +++ b/man/initiative_by.Rd @@ -7,6 +7,7 @@ initiative_by( initiative_data, by = "pays", + sep = ".", filter_var = NULL, filter_vals = NULL, node_size = c("type", "age"), @@ -32,47 +33,16 @@ initiative_by( \arguments{ \item{initiative_data}{a data frame object containing the initiative data} -\item{by}{} +\item{by}{the values around which nodes are formed} -\item{filter_var}{} +\item{filter_var}{filtered variable} -\item{filter_vals}{} +\item{filter_vals}{values associated to the filter} \item{node_size}{character string specifying the a column in the \code{initiative_data} data frame with some value to vary the node radius's with. See also \code{radiusCalculation}.} \item{group}{character string specifying the group of each node in the \code{initiative_data} data frame.} -\item{font_size}{} - -\item{height}{} - -\item{width}{} - -\item{colour_scale}{} - -\item{font_family}{} - -\item{link_distance}{} - -\item{link_width}{} - -\item{radius_calculation}{} - -\item{charge}{} - -\item{link_colour}{} - -\item{opacity}{} - -\item{zoom}{} - -\item{arrows}{} - -\item{bounded}{} - -\item{display_labels}{} - -\item{click_action}{} } \value{ Returns a network graph object diff --git a/man/replace_other.Rd b/man/replace_other.Rd new file mode 100644 index 0000000..3263aee --- /dev/null +++ b/man/replace_other.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/replace_other.R +\name{replace_other} +\alias{replace_other} +\title{"replace_other"} +\usage{ +replace_other( + data = individuals, + group = NULL, + group_other = paste0("autre_", group), + group_other_name = NULL, + RAS = FALSE +) +} +\arguments{ +\item{data}{The data frame in which the replacement will be performed. By default, it assumes a data frame called \code{individuals}.} + +\item{group}{The name of the group variable to be replaced. This parameter is required.} + +\item{group_other}{The name of the replacement group variable. It is constructed by appending the prefix "autre_" to the original group name. For example, if \code{group} is "pays", then \code{group_other} becomes "autre_pays".} + +\item{group_other_name}{The specific value within the \code{group} variable that should be replaced. When this value is encountered in the \code{group} variable, it will be replaced with the corresponding value from \code{group_other}. This parameter is required.} + +\item{RAS}{A logical value indicating whether the replacement should be performed with "RAS" when the \code{group_other_name} is encountered. If \code{RAS} is set to \code{TRUE}, the replacement will be "RAS"; otherwise, it will be the corresponding value from \code{group_other}. By default, it is set to \code{FALSE}.} +} +\value{ +Returns data +} +\description{ +This function replaces a specific group in a data frame with another group. +} +\note{ +The \code{mutate} function is used to create a new column in the data frame named \code{group_var}, which replaces the values based on the provided conditions. When \code{RAS} is set to \code{TRUE}, it checks if the value in the \code{group} variable is equal to \code{group_other_name}. If it is, the corresponding value from \code{group_other} is assigned to \code{group_var}. Additionally, if the value in the \code{group} variable is \code{NA} (missing), it is replaced with "RAS". If \code{RAS} is set to \code{FALSE}, the replacement is performed without using "RAS". +} +\examples{ +# TODO +}