Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update vignette about knit_print for pkg author #1929

Closed
cderv opened this issue Dec 8, 2020 · 2 comments
Closed

Update vignette about knit_print for pkg author #1929

cderv opened this issue Dec 8, 2020 · 2 comments
Assignees
Labels
doc Need to improve documentation

Comments

@cderv
Copy link
Collaborator

cderv commented Dec 8, 2020

Context

R 3.6 and R 4.0 have change things for S3 methods lookup and the search is not more used.

This has caused so issue in certain packages that where not following closely the advice in the vignette
vegawidget/vegawidget#132 (comment)

The vignette should be updated with more examples and mention of the importance of exporting due to this new behavior
https://cran.r-project.org/web/packages/knitr/vignettes/knit_print.html#for-package-authors

Different solutions:

Import the generic and package export S3 method

@importFrom knitr knit_print
@export
knit_print.class <-

The package must be in Import in the DESCRIPTION file

Register the method dynamically

  • No easy way with base R and it uses internal function.
  • vctrs has a helper for that: register_s3_method - that can be copied - pasted as MIT licenced
  • R 3.6 + offers a function .S3method()

See examples for some of this:

Delayed registration

R 3.6 introduce a new way to use S3method in NAMESPACE: S3method(knitr::knit_print, class)

With rogygen2 it is

@exportS3Method knitr::knit_print
knit_print.class <- 
@cderv cderv added the doc Need to improve documentation label Dec 8, 2020
@cderv cderv self-assigned this Dec 8, 2020
@yihui
Copy link
Owner

yihui commented Feb 9, 2021

R 3.6 introduce a new way to use S3method in NAMESPACE: S3method(knitr::knit_print, class)

Oh I didn't know that. That seems to be the simplest method. From what I understand, it doesn't require knitr to be in Imports, I'd advocate this method. The requirement for R >= 3.6.0 doesn't sound too bad to me (v3.6.0 was released on 2019-04-26, which feels like a century ago now? :)

But other methods can certainly be mentioned in the vignette.

@yihui yihui assigned yihui and unassigned cderv Aug 31, 2023
@yihui yihui closed this as completed in 360176b Aug 31, 2023
@olivroy olivroy mentioned this issue Sep 19, 2023
5 tasks
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
doc Need to improve documentation
Projects
None yet
Development

No branches or pull requests

2 participants