R/read.cb.R

Defines functions read.cb

Documented in read.cb

#' Read from the clipboard
#' 
#' Read tabular data from the clipboard.
#' 
#' @param header A logical value indicating whether the file contains the names of the variables as its first line. Overrides the default \code{header=FALSE} option in \code{read.table()}.
#' @param ... Further arguments to be passed to \code{read.table}
#' 
#' @return A data.frame
#' 
#' @examples
#' \dontrun{
#' # To read CSV data with a header from the clipboard:
#' read.cb(header=TRUE, sep=',')
#' }
#' 
#' @export
read.cb <- function(header=TRUE, ...) {
    os <- Sys.info()[1]
    if (os=="Darwin")       content <- read.table(pipe("pbpaste"),  header=header, ...)
    else if (os=="Windows") content <- read.table(file="clipboard", header=header, ...)
    else stop("Sorry, only works on Windows and Mac.")
    content <- tibble::as_tibble(content)
    return(content)
}

Try the Tmisc package in your browser

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

Tmisc documentation built on Aug. 23, 2023, 1:07 a.m.