diff --git a/DESCRIPTION b/DESCRIPTION index b6f8bc3..b1c0a95 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,13 +22,20 @@ License: BSD_3_clause + file LICENSE LazyData: TRUE Depends: R (>= 3.3) Imports: - Rcpp (>= 0.12.2), stringi, RcppParallel, - htmlwidgets (>= 0.6), -LinkingTo: Rcpp, RcppParallel + Rcpp (>= 0.12.2), + stringi, + RcppParallel +LinkingTo: + Rcpp, + RcppParallel Suggests: - knitr (>= 1.12.3),testthat, - rmarkdown (>= 0.9.5),microbenchmark, - ggplot2, directlabels + htmlwidgets (>= 0.6), + knitr (>= 1.12.3), + testthat, + rmarkdown (>= 0.9.5), + microbenchmark, + ggplot2, + directlabels URL: https://github.com/qinwf/re2r/ BugReports: https://github.com/qinwf/re2r/issues VignetteBuilder: knitr diff --git a/R/widget.R b/R/widget.R index 4175c47..ed3979d 100644 --- a/R/widget.R +++ b/R/widget.R @@ -34,11 +34,15 @@ remove_named = function(string){ #' @export show_regex <- function(pattern, width = NULL, height = NULL) { - if (is.character(pattern)){ + if (!requireNamespace("htmlwidgets", quietly = TRUE)) { + stop("'htmlwidgets' package is not installed.") + } + + if (is.character(pattern)) { res = re2(pattern) - }else if (inherits(pattern,"re2c")) { + } else if (inherits(pattern,"re2c")) { res = pattern - } else if (is.list(pattern)){ + } else if (is.list(pattern)) { return(show_regex(pattern[[1]], width, height)) } else { stop("pattern is a string or a pre-compiled regular expression.") diff --git a/R/zzz.R b/R/zzz.R index 1c574bf..d26f5a8 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -32,7 +32,6 @@ ##' @useDynLib re2r ##' @import Rcpp -##' @import htmlwidgets ##' @importFrom stringi stri_enc_toutf8 ##' @importFrom RcppParallel RcppParallelLibs NULL diff --git a/tests/testthat/test-show.R b/tests/testthat/test-show.R index ffaf37f..d8f4215 100644 --- a/tests/testthat/test-show.R +++ b/tests/testthat/test-show.R @@ -1,6 +1,7 @@ context("test show regex") test_that("test show_regex",{ + skip_if_not_installed("htmlwidgets") show_regex(re2("(?P>this)( is)(?P>this)")) show_regex("show_regex") expect_error(show_regex(list()))