This is an extension to R operators +
, -
, |
, and @
to gain the ability to paste character vectors. This is useful when building queries for the PubMed database (see for example the rentrez package).
Get it from GitHub:
devtools::install_github("jchrom/qbuildr")
Avoiding the explicit call to paste
makes the code much cleaner:
library(qbuildr)
query = "eeg" + "epilepsy" - "temporal"
cat(query)
#> eeg AND epilepsy NOT temporal
The @
operator can be used to add field specification:
query = "eeg" @ "TIAB" + "epilepsy" @ "MeSH"
cat(query)
#> eeg[TIAB] AND epilepsy[MeSH]
You can build nested queries using the g
function (for "group"). You can add field specification to multiple terms at once by providing a character vector:
query = "pain" @ "TIAB" +
g("eeg" | "seeg", "MeSH") -
g("mri" | "fmri" | "meg", "TIAB")
cat(query)
#> pain[TIAB] AND (eeg[MeSH] OR seeg[MeSH]) NOT (mri[TIAB] OR fmri[TIAB] OR meg[TIAB])
Operators still work the usual way with numeric or logical inputs, but they may be slower, so beware:
# With redefined operators
system.time(runif(10^7) + runif(10^7))
#> user system elapsed
#> 0.988 0.028 1.020
# With original operators
detach("package:qbuildr", unload = TRUE)
system.time(runif(10^7) + runif(10^7))
#> user system elapsed
#> 0.888 0.008 0.896
The advantages and pitfalls of this approach are discussed here and here.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.