R/write_excel.R

Defines functions write_excel

Documented in write_excel

#' Write R data into excel
#'
#' @param x a data.frame to be copied to clipboard
#' @param row.names a logical indicating if row names should be included
#' @param col.names a logical indicating if column names should be included
#' @param ... other read.table options
#'
#' @return data.frame copied to clipboard
#' @export
#'
#' @description A function to easily copy data out of R into a spreadsheet.
#'              This should not be used within a reproducible work flow, instead
#'              it should only be used on an ad-hoc basis
#'              (note: I'm not aware of the original author of this function,
#'              it was taken directly from a stack overflow answer)
#'
#' @examples
#' # set dummy data
#'
#' set.seed(2)
#'
#' data = data.frame(date = sample(seq(as.Date("2017-03-01"), as.Date("2017-08-01"), 1), 20, replace = TRUE),
#'                   sex = sample(c("Female", "Male"), 20, replace = TRUE))
#'
#' # apply function to write data to clipboard
#'
#' write_excel(data)
#'
#' # now paste data into a spreadsheet (i.e. open a spreadsheet and press ctrl + v)
write_excel <- function(x, row.names=FALSE, col.names=TRUE, ...) {

  write.table(x, "clipboard", sep="\t", row.names = row.names,
              col.names = col.names, ...)

}
DanielGardiner/HelperFunc documentation built on May 23, 2019, 2:42 p.m.