R/astext.R

Defines functions astext

Documented in astext

#' As Text
#' 
#' Prints a vector as text you can copy and paste back into the code. Helpful for copying vectors into code for testing and validation.
#' Author: Bryce Chamberlain.
#'
#' @param x Vector to represent as text.
#'
#' @return Vector represented as a character.
#' @export
#'
#' @examples
#' astext( c( 1, 2, 4 ) )
#' astext( c( 'a', 'b', 'c' ) )
astext = function( x ) if( is.numeric(x) ){
  as.character(glue::glue( 'c( { paste0( x, collapse = ", " ) } )' ))
} else {
  as.character(glue::glue( "c( '{ paste0( x, collapse = \"', '\" ) }' )" ))
}

Try the easyr package in your browser

Any scripts or data that you put into this service are public.

easyr documentation built on March 31, 2023, 6:22 p.m.