-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2a880c
commit 3803387
Showing
5 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: yulab.utils | ||
Title: Supporting Functions for Packages Maintained by 'YuLab-SMU' | ||
Version: 0.1.1.001 | ||
Version: 0.1.1.002 | ||
Authors@R: c(person("Guangchuang", "Yu", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6485-8781"))) | ||
Description: Miscellaneous functions commonly used by 'YuLab-SMU'. | ||
Imports: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
##' @rdname regexpr-style | ||
##' @export | ||
set_PCRE <- function() { | ||
options(regexpr_use_perl = TRUE) | ||
} | ||
|
||
##' @rdname regexpr-style | ||
##' @export | ||
set_TRE <- function() { | ||
options(regexpr_use_perl = FALSE) | ||
} | ||
|
||
##' @rdname regexpr-style | ||
##' @export | ||
use_perl <- function() { | ||
res <- getOption("regexpr_use_perl", default = auto_set_regexpr_style()) | ||
return(res) | ||
} | ||
|
||
|
||
##' switch regular expression style (PCRE vs TRE) | ||
##' | ||
##' The `set_regexpr_style()` allows user to specify which style to be used, | ||
##' while the `auto_set_regexpr_style()` automatically set the style depdending on | ||
##' the operating system (TRE for Windows and PCRE for other OSs (Linux and Mac)). | ||
##' | ||
##' `set_PCRE()` force to use PCRE style while `set_TRE()` force to use TRE. | ||
##' | ||
##' Note that all these functions are not change the behavior of `gsub()` and `regexpr()`. | ||
##' The functions are just set a global option to store the user's choice of whether using `perl = TRUE`. | ||
##' | ||
##' Users can access the option via `use_perl()` and pass the return value to `gusb()` or `regexpr()` to specify the style in use. | ||
##' | ||
##' @rdname regexpr-style | ||
##' @param style one of 'PCRE' or 'TRE' | ||
##' @return logical value of whether use perl | ||
##' @reference <https://stackoverflow.com/questions/47240375/regular-expressions-in-base-r-perl-true-vs-the-default-pcre-vs-tre> | ||
##' @export | ||
##' @author Guangchuang Yu | ||
set_regexpr_style <- function(style) { | ||
if (missing(style)) { | ||
message("style is not specific, set automatically.") | ||
auto_set_regexpr_style() | ||
} else { | ||
style <- match.arg(style, c("PCRE", "TRE")) | ||
if (style == "PCRE") { | ||
set_PCRE() | ||
} else { | ||
set_TRE() | ||
} | ||
} | ||
res <- getOption("regexpr_use_perl") | ||
invisible(res) | ||
} | ||
|
||
##' @rdname regexpr-style | ||
##' @export | ||
auto_set_regexpr_style <- function() { | ||
os <- Sys.info()[1] | ||
if (os == "Windows") { | ||
set_TRE() | ||
res <- FALSE | ||
} else { | ||
set_PCRE() | ||
res <- TRUE | ||
} | ||
invisible(res) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.