r-lib / generics

Common generic methods
https://generics.r-lib.org/
Other
61 stars 13 forks source link

Fix/pkgdown #28

Closed DavisVaughan closed 6 years ago

DavisVaughan commented 6 years ago

Two fixes for pkgdown to work.

1) For the \Sexpr blocks, we now say rd rather than Rd. pkgdown failed with Rd. This is the right way to specify the results section even though Rd works since whatever parses it does not seem to be case sensitive (maybe pkgdown should be more forgiving here and not be case sensitive either?).

2) When viewing development help interactively, pkgload:::shim_help() is being used. When this hits a method it cannot find documentation for, it errors. utils::help() returns a custom character object along with a message. We now use a tryCatch() when shim_help() is used, and return character() if no help is found. This was specifically added for the case of default methods that we export but dont document like:

library(generics)
library(pkgload)

# not an error!
help("as.factor.default", "generics")
#> No documentation for 'as.factor.default' in specified packages and libraries:
#> you could try '??as.factor.default'

str(help("as.factor.default", "generics"))
#>  'help_files_with_topic' chr(0) 
#>  - attr(*, "call")= language help(topic = "as.factor.default", package = "generics")
#>  - attr(*, "topic")= chr "as.factor.default"
#>  - attr(*, "tried_all_packages")= logi FALSE
#>  - attr(*, "type")= chr "text"

# (inside generics R Project)
# load dev generics, sorry about hard path
pkgload::load_all("~/Desktop/r/packages/generics")
#> Loading generics

# now using dev help
help("as.factor.default", "generics")
#> Error: Could not find development topic 'as.factor.default'

# and that called:
pkgload:::shim_help("as.factor.default", "generics")
#> Error: Could not find development topic 'as.factor.default'

I don't think this is an error on pkgload's part. It's fine to throw an error. But for generics, we pass every method that attr(utils::methods("as.factor"), "info") can find through help() to find the path to any help docs. This is also our way of actually determining if help docs even exist. So we don't want it to error if they don't exist, we just want to handle appropriately and not include in the dynamic Rd.