1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 06:06:12 +01:00
AMR/R/misc.R
dr. M.S. (Matthijs) Berends 53464ff1c8
- For functions first_isolate, EUCAST_rules the antibiotic column names are case-insensitive
- Functions `first_isolate`, `EUCAST_rules` and `rsi_predict` supports tidyverse-like evaluation of parameters (no need to quote columns them anymore)
- Functions `clipboard_import` and `clipboard_export` as helper functions to quickly copy and paste from/to software like Excel and SPSS
- Renamed dataset `bactlist` to `microorganisms`
2018-03-23 14:46:02 +01:00

53 lines
2.3 KiB
R

# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# AUTHORS #
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# LICENCE #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2.0, #
# as published by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# ==================================================================== #
# No export, no Rd
"%like%" <- function(vector, pattern) {
# Source: https://github.com/Rdatatable/data.table/blob/master/R/like.R
# But made it case insensitive
if (is.factor(vector)) {
as.integer(vector) %in% grep(pattern, levels(vector), ignore.case = TRUE)
} else {
grepl(pattern, vector, ignore.case = TRUE)
}
}
# No export, no Rd
percent <- function(x, round = 1, ...) {
base::paste0(base::round(x * 100, digits = round), "%")
}
# No export, no Rd
quasiquotate <- function(deparsed, parsed) {
# when text: remove first and last "
if (any(deparsed %like% '^".+"$' | deparsed %like% "^'.+'$")) {
deparsed <- deparsed %>% substr(2, nchar(.) - 1)
}
# apply if needed
if (any(!deparsed %like% '[[$:()]'
& !deparsed %in% c('""', "''", "", # empty text
".", ".data", # dplyr references
"TRUE", "FALSE", # logicals
"NA", "NaN", "NULL", # empty values
ls(.GlobalEnv)))) {
deparsed
} else {
parsed
}
}