usage of functions like `foo<-` should be treated with special care #38

Closed
yihui opened this Issue Aug 26, 2011 · 3 comments

4 participants

@yihui

currently roxygen2 generates usage like foo<-(x, value) for a function 'foo<-' <- function(x, value), but it really should be foo(x) <- value

@hadley hadley closed this in aed1db5 Oct 25, 2011
@daroczig

I am reopening this issue now based on @hadley's suggestion on SO.

If I roxygenise the following function:

#' Setter function
#' @param x an R object
#' @param value a character value to set
#' @export
`foo<-` <- function(x, value){
    attr(x, 'foo') <- value
    return(x)
}

I get the following Rd file:

\name{foo<-}
\alias{foo<-}
\title{Setter function}
\usage{
  foo(x, value) <- value
}
\arguments{
  \item{x}{an R object}

  \item{value}{a character value to set}
}
\description{
  Setter function
}

Where the usage tag is not formed correctly.

@hadley hadley reopened this Jun 4, 2012
@richierocks

This update to process.usage fixes the issue (for roxygen2).

process.usage <- function(partitum) {
  if (is.null(partitum$fun) || !partitum$fun) {
    return(new_tag("usage", NULL))
  }

  if (!is.null(partitum$usage)) {
    return(new_tag("usage", partitum$usage))
  }

  fun_name <- if (!is.null(partitum$method)) {
    rd_tag('method', partitum$method[[1]], partitum$method[[2]])
  } else {
    partitum$assignee
  }

  is_setter_fun <- str_detect(fun_name, fixed("<-"))
  if(is_setter_fun) {
    partitum$formals["value"] <- NULL
  }
  args <- usage(partitum$formals)

  if (is_setter_fun) {
    fun_name <- str_replace(fun_name, fixed("<-"), "")
    new_tag("usage", str_c(fun_name, "(", args, ") <- value"))
  } else {
    new_tag("usage", str_c(fun_name, "(", args, ")"))
  }
}
@hadley
Collaborator

Fixed in roxygen3 (https://github.com/hadley/roxygen3). This is not yet suitable for use, but it has (I think) a better design, so it's where I'm fixing bugs.

@hadley hadley closed this Aug 27, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment