diff --git a/R/clipboard.R b/R/clipboard.R index 70eae0e9..8a33c98d 100644 --- a/R/clipboard.R +++ b/R/clipboard.R @@ -14,6 +14,7 @@ #' @param startrow \emph{n}th row to start importing from. When \code{header = TRUE}, the import will start on row \code{startrow} \emph{below} the header. #' @param as_vector a logical value indicating whether data consisting of only one column should be imported as vector using \code{\link[dplyr]{pull}}. This will strip off the header. #' @param guess_col_types a logical value indicating whether column types should be guessed and transformed automatically with \code{\link[readr]{parse_guess}} from the \code{readr} package. Besides, the antimicrobial classes in this AMR package (\code{\link{as.rsi}} and \code{\link{as.mic}}) are also supported. +#' @param remove_ASCII_escape_char remove ASCII escape character #' @param info print info to console #' @keywords clipboard clipboard_import clipboard_export import export #' @importFrom dplyr %>% pull as_tibble @@ -58,6 +59,7 @@ #' clipboard_export() #' } clipboard_import <- function(sep = '\t', + quote = "", header = TRUE, dec = ".", na = c("", "NA", "NULL"), @@ -68,6 +70,7 @@ clipboard_import <- function(sep = '\t', date_names = 'en', date_format = '%Y-%m-%d', time_format = '%H:%M', + remove_ASCII_escape_char = FALSE, tz = Sys.timezone(), encoding = "UTF-8", info = TRUE) { @@ -80,6 +83,7 @@ clipboard_import <- function(sep = '\t', # this will fail when clipr is (still) not available import_tbl <- clipr::read_clip_tbl(file = file, sep = sep, + quote = quote, header = header, strip.white = TRUE, dec = dec, @@ -108,6 +112,7 @@ clipboard_import <- function(sep = '\t', decimal_mark = dec, tz = tz, encoding = encoding, + remove_ASCII_escape_char = remove_ASCII_escape_char, na = na) if (info == TRUE) { cat('OK\n') diff --git a/R/misc.R b/R/misc.R index ec8db1eb..751cac1f 100755 --- a/R/misc.R +++ b/R/misc.R @@ -119,6 +119,7 @@ tbl_parse_guess <- function(tbl, decimal_mark = '.', tz = Sys.timezone(), encoding = "UTF-8", + remove_ASCII_escape_char = FALSE, na = c("", "NA", "NULL")) { date_format <- date_generic(date_format) @@ -139,8 +140,10 @@ tbl_parse_guess <- function(tbl, if (any(tbl %>% pull(i) %>% class() %in% c('factor', 'character'))) { # get values distinct_val <- tbl %>% pull(i) %>% unique() %>% sort() - # remove ASCII escape character: https://en.wikipedia.org/wiki/Escape_character#ASCII_escape_character - tbl[, i] <- tbl %>% pull(i) %>% gsub('\033', ' ', ., fixed = TRUE) + if (remove_ASCII_escape_char == TRUE) { + # remove ASCII escape character: https://en.wikipedia.org/wiki/Escape_character#ASCII_escape_character + tbl[, i] <- tbl %>% pull(i) %>% gsub('\033', ' ', ., fixed = TRUE) + } # look for RSI, shouldn't all be "" and must be valid antibiotic interpretations if (!all(distinct_val[!is.na(distinct_val)] == '') & all(distinct_val[!is.na(distinct_val)] %in% c('', 'I', 'I;I', 'R', 'R;R', 'S', 'S;S'))) { diff --git a/man/clipboard.Rd b/man/clipboard.Rd index e730ab56..75cd0201 100644 --- a/man/clipboard.Rd +++ b/man/clipboard.Rd @@ -6,11 +6,12 @@ \alias{clipboard_export} \title{Import/export from clipboard} \usage{ -clipboard_import(sep = "\\t", header = TRUE, dec = ".", na = c("", "NA", - "NULL"), stringsAsFactors = FALSE, startrow = 1, as_vector = TRUE, - guess_col_types = TRUE, date_names = "en", date_format = "\%Y-\%m-\%d", - time_format = "\%H:\%M", tz = Sys.timezone(), encoding = "UTF-8", - info = TRUE) +clipboard_import(sep = "\\t", quote = "", header = TRUE, dec = ".", + na = c("", "NA", "NULL"), stringsAsFactors = FALSE, startrow = 1, + as_vector = TRUE, guess_col_types = TRUE, date_names = "en", + date_format = "\%Y-\%m-\%d", time_format = "\%H:\%M", + remove_ASCII_escape_char = FALSE, tz = Sys.timezone(), + encoding = "UTF-8", info = TRUE) clipboard_export(x, sep = "\\t", dec = ".", na = "", header = TRUE, info = TRUE) @@ -21,6 +22,12 @@ clipboard_export(x, sep = "\\t", dec = ".", na = "", header = TRUE, default for \code{read.table}) the separator is \sQuote{white space}, that is one or more spaces, tabs, newlines or carriage returns.} +\item{quote}{the set of quoting characters. To disable quoting + altogether, use \code{quote = ""}. See \code{\link{scan}} for the + behaviour on quotes embedded in quotes. Quoting is only considered + for columns read as character, which is all of them unless + \code{colClasses} is specified.} + \item{header}{a logical value indicating whether the file contains the names of the variables as its first line. If missing, the value is determined from the file format: \code{header} is set to \code{TRUE} @@ -50,6 +57,8 @@ or an object created by \code{\link[=date_names]{date_names()}}.} \item{time_format}{Default date and time formats.} +\item{remove_ASCII_escape_char}{remove ASCII escape character} + \item{tz}{Default tz. This is used both for input (if the time zone isn't present in individual strings), and for output (to control the default display). The default is to use "UTC", a time zone that does not use