R/testDF.R

#' testDF, a function for creating a data frame for mucking around with.
#'
#' @param rows how big should the data frame be
#' @param DT should the output be a data.table? (data.frame is output if FALSE)
#' @importFrom data.table setDT
#' @importFrom stats rnorm
#' @export
#' 

testDF <- function( rows, DT = FALSE ) {
    
    df <- data.frame(
        strings = sapply( seq_len( rows ),
                          function(x) {
                              paste( sample( letters, 4, replace = TRUE ), collapse = "" )
                          } ),
        ints = sample( x = seq.int( from = 1000L, to = 9999L, by = 1L ),
                       size = rows,
                       replace = TRUE ),
        rands = rnorm( rows ),
        stringsAsFactors = FALSE
    )
    
    if( DT ) {
        setDT( df )
    }
    
    return( df )
    
}
rossholmberg/holmberg documentation built on May 27, 2019, 11:34 p.m.