Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Re-document with latest roxygen2 features #310

Merged
merged 6 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +11 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glue doesn't (and cannot) depend on testthat, vctrs, waldo, etc. It feels like we're dismantling the conditional and delayed export of these methods and are, instead, assuming that these packages are available.

Am I out of the loop and this is actually OK now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly the point of this form of S3method() 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon further research, this is roxygen2 newly taking advantage of a feature that appeared in R 3.6:

https://rstudio.github.io/r-manuals/r-exts/Creating-R-packages.html#registering-s3-methods

As from R 3.6.0 one can also use S3method() directives to perform delayed registration. With

if(getRversion() >= "3.6.0") {
    S3method(pkg::gen, cls)
}

function gen.cls will get registered as an S3 method for class cls and generic gen from package pkg only when the namespace of pkg is loaded. This can be employed to deal with situations where the method is not “immediately” needed, and having to pre-load the namespace of pkg (and all its strong dependencies) in order to perform immediate registration is considered too onerous.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, really old then 😆

export(as_glue)
export(backtick)
export(double_quote)
Expand Down
154 changes: 0 additions & 154 deletions R/compat-s3-register.R

This file was deleted.

6 changes: 6 additions & 0 deletions R/glue-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
## usethis namespace: end
NULL
9 changes: 0 additions & 9 deletions R/glue.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ 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
}
NextMethod("compare")
}

## @export
#' @exportS3Method waldo::compare_proxy
compare_proxy.glue <- function(x, path = "x") {
class(x) <- NULL
NextMethod("compare_proxy")
Expand Down
9 changes: 6 additions & 3 deletions R/vctrs.R
Original file line number Diff line number Diff line change
@@ -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)
}
10 changes: 0 additions & 10 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -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")) {
Expand Down
10 changes: 0 additions & 10 deletions man/glue-deprecated.Rd

This file was deleted.

35 changes: 35 additions & 0 deletions man/glue-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading