mirror of https://github.com/msberends/AMR.git
clipboard update
This commit is contained in:
parent
8421638b60
commit
03a3cb397b
|
@ -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 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 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 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
|
#' @param info print info to console
|
||||||
#' @keywords clipboard clipboard_import clipboard_export import export
|
#' @keywords clipboard clipboard_import clipboard_export import export
|
||||||
#' @importFrom dplyr %>% pull as_tibble
|
#' @importFrom dplyr %>% pull as_tibble
|
||||||
|
@ -58,6 +59,7 @@
|
||||||
#' clipboard_export()
|
#' clipboard_export()
|
||||||
#' }
|
#' }
|
||||||
clipboard_import <- function(sep = '\t',
|
clipboard_import <- function(sep = '\t',
|
||||||
|
quote = "",
|
||||||
header = TRUE,
|
header = TRUE,
|
||||||
dec = ".",
|
dec = ".",
|
||||||
na = c("", "NA", "NULL"),
|
na = c("", "NA", "NULL"),
|
||||||
|
@ -68,6 +70,7 @@ clipboard_import <- function(sep = '\t',
|
||||||
date_names = 'en',
|
date_names = 'en',
|
||||||
date_format = '%Y-%m-%d',
|
date_format = '%Y-%m-%d',
|
||||||
time_format = '%H:%M',
|
time_format = '%H:%M',
|
||||||
|
remove_ASCII_escape_char = FALSE,
|
||||||
tz = Sys.timezone(),
|
tz = Sys.timezone(),
|
||||||
encoding = "UTF-8",
|
encoding = "UTF-8",
|
||||||
info = TRUE) {
|
info = TRUE) {
|
||||||
|
@ -80,6 +83,7 @@ clipboard_import <- function(sep = '\t',
|
||||||
# this will fail when clipr is (still) not available
|
# this will fail when clipr is (still) not available
|
||||||
import_tbl <- clipr::read_clip_tbl(file = file,
|
import_tbl <- clipr::read_clip_tbl(file = file,
|
||||||
sep = sep,
|
sep = sep,
|
||||||
|
quote = quote,
|
||||||
header = header,
|
header = header,
|
||||||
strip.white = TRUE,
|
strip.white = TRUE,
|
||||||
dec = dec,
|
dec = dec,
|
||||||
|
@ -108,6 +112,7 @@ clipboard_import <- function(sep = '\t',
|
||||||
decimal_mark = dec,
|
decimal_mark = dec,
|
||||||
tz = tz,
|
tz = tz,
|
||||||
encoding = encoding,
|
encoding = encoding,
|
||||||
|
remove_ASCII_escape_char = remove_ASCII_escape_char,
|
||||||
na = na)
|
na = na)
|
||||||
if (info == TRUE) {
|
if (info == TRUE) {
|
||||||
cat('OK\n')
|
cat('OK\n')
|
||||||
|
|
7
R/misc.R
7
R/misc.R
|
@ -119,6 +119,7 @@ tbl_parse_guess <- function(tbl,
|
||||||
decimal_mark = '.',
|
decimal_mark = '.',
|
||||||
tz = Sys.timezone(),
|
tz = Sys.timezone(),
|
||||||
encoding = "UTF-8",
|
encoding = "UTF-8",
|
||||||
|
remove_ASCII_escape_char = FALSE,
|
||||||
na = c("", "NA", "NULL")) {
|
na = c("", "NA", "NULL")) {
|
||||||
|
|
||||||
date_format <- date_generic(date_format)
|
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'))) {
|
if (any(tbl %>% pull(i) %>% class() %in% c('factor', 'character'))) {
|
||||||
# get values
|
# get values
|
||||||
distinct_val <- tbl %>% pull(i) %>% unique() %>% sort()
|
distinct_val <- tbl %>% pull(i) %>% unique() %>% sort()
|
||||||
# remove ASCII escape character: https://en.wikipedia.org/wiki/Escape_character#ASCII_escape_character
|
if (remove_ASCII_escape_char == TRUE) {
|
||||||
tbl[, i] <- tbl %>% pull(i) %>% gsub('\033', ' ', ., fixed = 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
|
# look for RSI, shouldn't all be "" and must be valid antibiotic interpretations
|
||||||
if (!all(distinct_val[!is.na(distinct_val)] == '')
|
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'))) {
|
& all(distinct_val[!is.na(distinct_val)] %in% c('', 'I', 'I;I', 'R', 'R;R', 'S', 'S;S'))) {
|
||||||
|
|
|
@ -6,11 +6,12 @@
|
||||||
\alias{clipboard_export}
|
\alias{clipboard_export}
|
||||||
\title{Import/export from clipboard}
|
\title{Import/export from clipboard}
|
||||||
\usage{
|
\usage{
|
||||||
clipboard_import(sep = "\\t", header = TRUE, dec = ".", na = c("", "NA",
|
clipboard_import(sep = "\\t", quote = "", header = TRUE, dec = ".",
|
||||||
"NULL"), stringsAsFactors = FALSE, startrow = 1, as_vector = TRUE,
|
na = c("", "NA", "NULL"), stringsAsFactors = FALSE, startrow = 1,
|
||||||
guess_col_types = TRUE, date_names = "en", date_format = "\%Y-\%m-\%d",
|
as_vector = TRUE, guess_col_types = TRUE, date_names = "en",
|
||||||
time_format = "\%H:\%M", tz = Sys.timezone(), encoding = "UTF-8",
|
date_format = "\%Y-\%m-\%d", time_format = "\%H:\%M",
|
||||||
info = TRUE)
|
remove_ASCII_escape_char = FALSE, tz = Sys.timezone(),
|
||||||
|
encoding = "UTF-8", info = TRUE)
|
||||||
|
|
||||||
clipboard_export(x, sep = "\\t", dec = ".", na = "", header = TRUE,
|
clipboard_export(x, sep = "\\t", dec = ".", na = "", header = TRUE,
|
||||||
info = 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},
|
default for \code{read.table}) the separator is \sQuote{white space},
|
||||||
that is one or more spaces, tabs, newlines or carriage returns.}
|
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
|
\item{header}{a logical value indicating whether the file contains the
|
||||||
names of the variables as its first line. If missing, the value is
|
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}
|
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{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
|
\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
|
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
|
display). The default is to use "UTC", a time zone that does not use
|
||||||
|
|
Loading…
Reference in New Issue