#' Set the text attribute of a selector
#'
#' Given a selector object, set its text attribute
#'
#' @param selector An object of class selector
#' @param text A non-null character vector (or coercible to one). The vector must be
#' of the same length as the data stored in the selector object
#'
#' @return A selector object
#' @export
#'
#' @examples my_selector %>% set_text(c(1,2,3))
set_text <- function(selector, text){
#checks
check_setting(selector, text)
text <- as.character(text)
set(selector, 'text', text)
}
#' Set the id attribute of a selector
#'
#' Given a selector object, set its id attribute
#'
#' @param selector An object of class selector
#' @param id A non-null character vector, or coercible to one
#'
#' @return A selector object
#' @export
#'
#' @examples my_selector %>% set_id(c(1,2,3))
set_id <- function(selector, id){
check_setting(selector, id)
id <- as.character(id)
set(selector, 'id', id)
}
check_setting <- function(selector, col){
if (!inherits(selector, 'selector')){
stop('Error: I need a selector object in the first argument')
}
if (!is.vector(col)){
stop('Error: text must be a vector')
}
if (length(col) != nrow(selector$data)){
stop('The provided text vector does not have the same length as the
number of rows in the data')
}
}
#Setters and getters generics
set <- function(selector, attribute, value){
UseMethod('set', selector)
}
set.selector <- function(selector, attribute, value){
selector[[attribute]] <- value
selector
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.