diff --git a/NAMESPACE b/NAMESPACE index 3e5f401d..0ee7a78c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,14 @@ S3method(as_glue,character) S3method(as_glue,default) S3method(as_glue,glue) S3method(print,glue) +S3method(testthat::compare,glue) +S3method(vctrs::vec_cast,character.glue) +S3method(vctrs::vec_cast,glue.character) +S3method(vctrs::vec_cast,glue.glue) +S3method(vctrs::vec_ptype2,character.glue) +S3method(vctrs::vec_ptype2,glue.character) +S3method(vctrs::vec_ptype2,glue.glue) +S3method(waldo::compare_proxy,glue) export(as_glue) export(backtick) export(double_quote) diff --git a/R/compat-s3-register.R b/R/compat-s3-register.R deleted file mode 100644 index 50e0c1e5..00000000 --- a/R/compat-s3-register.R +++ /dev/null @@ -1,154 +0,0 @@ -# This source code file is licensed under the unlicense license -# https://unlicense.org - -# nocov start - -#' Register a method for a suggested dependency -#' -#' Generally, the recommended way to register an S3 method is to use the -#' `S3Method()` namespace directive (often generated automatically by the -#' `@export` roxygen2 tag). However, this technique requires that the generic -#' be in an imported package, and sometimes you want to suggest a package, -#' and only provide a method when that package is loaded. `s3_register()` -#' can be called from your package's `.onLoad()` to dynamically register -#' a method only if the generic's package is loaded. -#' -#' For R 3.5.0 and later, `s3_register()` is also useful when demonstrating -#' class creation in a vignette, since method lookup no longer always involves -#' the lexical scope. For R 3.6.0 and later, you can achieve a similar effect -#' by using "delayed method registration", i.e. placing the following in your -#' `NAMESPACE` file: -#' -#' ``` -#' if (getRversion() >= "3.6.0") { -#' S3method(package::generic, class) -#' } -#' ``` -#' -#' @section Usage in other packages: -#' To avoid taking a dependency on vctrs, you copy the source of -#' [`s3_register()`](https://github.com/r-lib/rlang/blob/master/R/compat-register.R) -#' into your own package. It is licensed under the permissive -#' [unlicense](https://choosealicense.com/licenses/unlicense/) to make it -#' crystal clear that we're happy for you to do this. There's no need to include -#' the license or even credit us when using this function. -#' -#' @param generic Name of the generic in the form `"pkg::generic"`. -#' @param class Name of the class -#' @param method Optionally, the implementation of the method. By default, -#' this will be found by looking for a function called `generic.class` -#' in the package environment. -#' @examples -#' # A typical use case is to dynamically register tibble/pillar methods -#' # for your class. That way you avoid creating a hard dependency on packages -#' # that are not essential, while still providing finer control over -#' # printing when they are used. -#' -#' .onLoad <- function(...) { -#' s3_register("pillar::pillar_shaft", "vctrs_vctr") -#' s3_register("tibble::type_sum", "vctrs_vctr") -#' } -#' @keywords internal -#' @noRd -s3_register <- function(generic, class, method = NULL) { - stopifnot(is.character(generic), length(generic) == 1) - stopifnot(is.character(class), length(class) == 1) - - pieces <- strsplit(generic, "::")[[1]] - stopifnot(length(pieces) == 2) - package <- pieces[[1]] - generic <- pieces[[2]] - - caller <- parent.frame() - - get_method_env <- function() { - top <- topenv(caller) - if (isNamespace(top)) { - asNamespace(environmentName(top)) - } else { - caller - } - } - get_method <- function(method, env) { - if (is.null(method)) { - get(paste0(generic, ".", class), envir = get_method_env()) - } else { - method - } - } - - register <- function(...) { - envir <- asNamespace(package) - - # Refresh the method each time, it might have been updated by - # `devtools::load_all()` - method_fn <- get_method(method) - stopifnot(is.function(method_fn)) - - - # Only register if generic can be accessed - if (exists(generic, envir)) { - registerS3method(generic, class, method_fn, envir = envir) - } else if (identical(Sys.getenv("NOT_CRAN"), "true")) { - warn <- .rlang_s3_register_compat("warn") - - warn(c( - sprintf( - "Can't find generic `%s` in package %s to register S3 method.", - generic, - package - ), - "i" = "This message is only shown to developers using devtools.", - "i" = sprintf("Do you need to update %s to the latest version?", package) - )) - } - } - - # Always register hook in case package is later unloaded & reloaded - setHook(packageEvent(package, "onLoad"), function(...) { - register() - }) - - # Avoid registration failures during loading (pkgload or regular). - # Check that environment is locked because the registering package - # might be a dependency of the package that exports the generic. In - # that case, the exports (and the generic) might not be populated - # yet (#1225). - if (isNamespaceLoaded(package) && environmentIsLocked(asNamespace(package))) { - register() - } - - invisible() -} - -.rlang_s3_register_compat <- function(fn) { - # Compats that behave the same independently of rlang's presence - out <- switch( - fn, - is_installed = return(function(pkg) requireNamespace(pkg, quietly = TRUE)) - ) - - # Fall back to base compats - - is_interactive_compat <- function() { - opt <- getOption("rlang_interactive") - if (!is.null(opt)) { - opt - } else { - interactive() - } - } - - format_msg <- function(x) paste(x, collapse = "\n") - switch( - fn, - is_interactive = return(is_interactive_compat), - abort = return(function(msg) stop(format_msg(msg), call. = FALSE)), - warn = return(function(msg) warning(format_msg(msg), call. = FALSE)), - inform = return(function(msg) message(format_msg(msg))) - ) - - stop(sprintf("Internal error in rlang shims: Unknown function `%s()`.", fn)) -} - -# nocov end diff --git a/R/glue-package.R b/R/glue-package.R new file mode 100644 index 00000000..a65cf643 --- /dev/null +++ b/R/glue-package.R @@ -0,0 +1,6 @@ +#' @keywords internal +"_PACKAGE" + +## usethis namespace: start +## usethis namespace: end +NULL diff --git a/R/glue.R b/R/glue.R index 06512fb5..1f7335ef 100644 --- a/R/glue.R +++ b/R/glue.R @@ -373,12 +373,3 @@ as.character.glue <- function(x, ...) { #' @importFrom methods setOldClass setOldClass(c("glue", "character")) - - -#' Deprecated Functions -#' -#' These functions are Deprecated in this release of glue, they will be removed -#' in a future version. -#' @name glue-deprecated -#' @keywords internal -NULL diff --git a/R/utils.R b/R/utils.R index 9f0138cc..065ac7cb 100644 --- a/R/utils.R +++ b/R/utils.R @@ -75,7 +75,7 @@ delayed_assign <- function(x, value, eval.env = parent.frame(1), assign.env = pa do.call(delayedAssign, list(x, value, eval.env, assign.env)) } -## @export +#' @exportS3Method testthat::compare compare.glue <- function(x, y, ...) { if (identical(class(y), "character")) { class(x) <- NULL @@ -83,7 +83,7 @@ compare.glue <- function(x, y, ...) { NextMethod("compare") } -## @export +#' @exportS3Method waldo::compare_proxy compare_proxy.glue <- function(x, path = "x") { class(x) <- NULL NextMethod("compare_proxy") diff --git a/R/vctrs.R b/R/vctrs.R index 7fcbf3bd..baf861f6 100644 --- a/R/vctrs.R +++ b/R/vctrs.R @@ -1,23 +1,26 @@ - -# Registered in .onLoad() - +#' @exportS3Method vctrs::vec_ptype2 vec_ptype2.glue.glue <- function(x, y, ...) { x } +#' @exportS3Method vctrs::vec_ptype2 vec_ptype2.glue.character <- function(x, y, ...) { x } +#' @exportS3Method vctrs::vec_ptype2 vec_ptype2.character.glue <- function(x, y, ...) { y } # Note order of class is the opposite as for ptype2 +#' @exportS3Method vctrs::vec_cast vec_cast.glue.glue <- function(x, to, ...) { x } +#' @exportS3Method vctrs::vec_cast vec_cast.glue.character <- function(x, to, ...) { as_glue(x) } +#' @exportS3Method vctrs::vec_cast vec_cast.character.glue <- function(x, to, ...) { unclass(x) } diff --git a/R/zzz.R b/R/zzz.R index 41751938..671f19fb 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,15 +1,5 @@ # nocov start .onLoad <- function(...) { - s3_register("testthat::compare", "glue") - - s3_register("waldo::compare_proxy", "glue") - - s3_register("vctrs::vec_ptype2", "glue.glue") - s3_register("vctrs::vec_ptype2", "character.glue") - s3_register("vctrs::vec_ptype2", "glue.character") - s3_register("vctrs::vec_cast", "glue.glue") - s3_register("vctrs::vec_cast", "character.glue") - s3_register("vctrs::vec_cast", "glue.character") if (isNamespaceLoaded("knitr") && "knit_engines" %in% getNamespaceExports("knitr")) { diff --git a/man/glue-deprecated.Rd b/man/glue-deprecated.Rd deleted file mode 100644 index ed8d75f8..00000000 --- a/man/glue-deprecated.Rd +++ /dev/null @@ -1,10 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/glue.R -\name{glue-deprecated} -\alias{glue-deprecated} -\title{Deprecated Functions} -\description{ -These functions are Deprecated in this release of glue, they will be removed -in a future version. -} -\keyword{internal} diff --git a/man/glue-package.Rd b/man/glue-package.Rd new file mode 100644 index 00000000..0e3ce602 --- /dev/null +++ b/man/glue-package.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/glue-package.R +\docType{package} +\name{glue-package} +\alias{glue-package} +\title{glue: Interpreted String Literals} +\description{ +\if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} + +An implementation of interpreted string literals, inspired by Python's Literal String Interpolation \url{https://www.python.org/dev/peps/pep-0498/} and Docstrings \url{https://www.python.org/dev/peps/pep-0257/} and Julia's Triple-Quoted String Literals \url{https://docs.julialang.org/en/v1.3/manual/strings/#Triple-Quoted-String-Literals-1}. +} +\seealso{ +Useful links: +\itemize{ + \item \url{https://glue.tidyverse.org/} + \item \url{https://github.com/tidyverse/glue} + \item Report bugs at \url{https://github.com/tidyverse/glue/issues} +} + +} +\author{ +\strong{Maintainer}: Jennifer Bryan \email{jenny@posit.co} (\href{https://orcid.org/0000-0002-6983-2759}{ORCID}) + +Authors: +\itemize{ + \item Jim Hester (\href{https://orcid.org/0000-0002-2739-7082}{ORCID}) +} + +Other contributors: +\itemize{ + \item Posit Software, PBC [copyright holder, funder] +} + +} +\keyword{internal}