R/df_to_clip.r

Defines functions df_to_clip

Documented in df_to_clip

#' Copy a data.frame to the clipboard
#'
#' @param df A data.frame
#' @param digits number of digits for rounding numerical columns
#'
#' @return the data.frame is copied to the clipboard allowing for easy pasting into excel (and subsequently to ppt, etc.)
#' @export
#'
df_to_clip <- function(df, digits=4) {
        nums <- vapply(df, is.numeric, FUN.VALUE = logical(1))
        df[,nums] <- round(df[,nums], digits = digits)
        write.table(x=df, file="clipboard", sep="\t", row.names = F)
}

Try the GNGTools package in your browser

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

GNGTools documentation built on Dec. 16, 2022, 5:09 p.m.