Skip to content

Loading…

Wrap \usage string and alias for S4 classes and methods #26

Closed
wants to merge 2 commits into from

2 participants

@eusebe

Please consider this patch which should fix #21
and fix alias for S4 classes and methods (http://cran.r-project.org/doc/manuals/R-exts.html#Documenting-S4-classes-and-methods)

David

@eusebe

I've just seen that there is a little bug with the first commit. For S3 method, the Rd file looks like:

\usage{
  \method{print}{foo}
(x, a = "sdmldsflkjmsqdlkfjk", b = "fmqlk", c = "\n\np. \n\n", ...)
}

There is a newline after \method, producing a warning with R CMD check. I've been looking and looking, but I can't see where this newline comes from...

@eusebe

With the development version of roxygen, it seems that S4 classes and methods are not documented correctly. \alias{} should be of the form:
theclass-class
generic,signature_list-method

Consequently, my classes and methods appear not documented with R CMD check:

* checking for missing documentation entries ... WARNING
Undocumented S4 methods:
  generic 'print' and siglist 'Report'
  generic 'print' and siglist 'asciiCbind'
...

I tried to make a (possibly not very elegant) patch for this, is there a chance that it is considered for inclusion?

@hadley hadley commented on the diff
R/rd-tag-api.R
@@ -96,7 +96,10 @@ format_wrap <- function(x, ...) {
#' @S3method format usage_tag
format.description_tag <- format_collapse
format.details_tag <- format_collapse
-format.usage_tag <- format_collapse
+format.usage_tag <- function(x, ...) {
+ values <- str_c(x$values, collapse = "\n\n ")
+ rd_tag(x$tag, paste(" ", values, sep = ""), space = TRUE)
@hadley Collaborator
hadley added a note

Could you please use str_c here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@hadley
Collaborator

Would you mind also including a few test cases?

@hadley
Collaborator

Closing because I think the usage issue has been dealt with, and S4 needs deeper changes.

@hadley hadley closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 3 deletions.
  1. +4 −1 R/rd-tag-api.R
  2. +7 −1 R/roclet-rd.R
  3. +4 −1 R/utils.R
View
5 R/rd-tag-api.R
@@ -96,7 +96,10 @@ format_wrap <- function(x, ...) {
#' @S3method format usage_tag
format.description_tag <- format_collapse
format.details_tag <- format_collapse
-format.usage_tag <- format_collapse
+format.usage_tag <- function(x, ...) {
+ values <- str_c(x$values, collapse = "\n\n ")
+ rd_tag(x$tag, paste(" ", values, sep = ""), space = TRUE)
@hadley Collaborator
hadley added a note

Could you please use str_c here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+}
# Tags that don't have output ------------------------------------------------
View
8 R/roclet-rd.R
@@ -327,7 +327,13 @@ roclet_rd_one <- function(partitum, base_path) {
filename <- str_c(partitum$merge %||% partitum$rdname %||% name, ".Rd")
add_tag(rd, new_tag("name", name))
- add_tag(rd, new_tag("alias", name))
+ # alias is not name for S4 classes and methods...
+ alias <- name
+ if (!is.null(partitum$S4class))
+ alias <- paste(alias, "-class", sep = "")
+ if (!is.null(partitum$S4method))
+ alias <- paste(alias, ",", partitum$signature, "-method", sep = "")
+ add_tag(rd, new_tag("alias", alias))
add_tag(rd, new_tag("formals", names(partitum$formals)))
add_tag(rd, process_description(partitum, base_path))
View
5 R/utils.R
@@ -22,7 +22,10 @@ usage <- function(args) {
arg_values <- vapply(args, arg_to_text, character(1))
- paste(names(args), arg_values, collapse = ", ", sep = "")
+ results <- paste(names(args), arg_values, sep = "")
+ cuml <- cumsum(nchar(results))
+ results <- split(results, cuml %/% 60)
+ paste(lapply(results, paste, collapse = ", "), collapse = ", \n ")
}
# Does the string contain no matter, but very well [:space:]?
Something went wrong with that request. Please try again.