cboettig / knitcitations

:package: Generate citations for knitr markdown and html files
http://carlboettiger.info
Other
220 stars 28 forks source link

Suggested handling of page numbers #32

Closed trinker closed 11 years ago

trinker commented 11 years ago

I love the package. I have a feature request.

It would add functionality if the package could handle a single or series of page numbers as you would have with LaTeX in that:

\cite[pp. 14-15]{cboettiger2013}

may give:

(Boettiger, 2013, pp. 14-15)
cboettig commented 11 years ago

Thanks for the suggestion. Here's two options for implementing this:

I could on citep add something that works like this:

citep("10.1016/j.tpb.2013.02.004", pp="14-15")

which would generate (Schreiber & Killingback, 2013, pp. 14-15). Or I could have a more generic way to add text which would require a bit more typing:

citep("10.1016/j.tpb.2013.02.004", end="pp. 14-15")

Which would generate the same text, (Schreiber & Killingback, 2013, pp. 14-15), but could also be modified to generate parenthetical comments like (Schreiber & Killingback, 2013, provide a good overview of this approach)

I'm not sure if the latter case is useful or not.

trinker commented 11 years ago

The former appears to be more explicit to the users but perhaps the argument could be page rather than pp Then some regexing, something along the lines of:

page <- "14-19"

pgs <- ifelse(grepl("-", page), "pp.", "p.")
paste(pgs, page)

#or single page...

page <- "1234"

pgs <- ifelse(grepl("-", page), "pp.", "p.")
paste(pgs, page)

would format the pages correctly. I can't think of another use of the last space in a parenthetical citation (in APA style), beyond pages, thus it seems your the explicit argument of page or pages may be the most coherent. That being said I may be missing a corner case usage for the later, more general end argument. Your example use beyond pages is a point well taken and I'm not sure if the flexibility or the ease of use is a better fit for knitcitations. Perhaps both a page and end argument, though this may be making it convoluted.

cboettig commented 11 years ago

Thanks for the feedback. Added this following the formatting you suggested in the most recent commit. Currently added only to parenthetical citations, let me know if such a use case also makes sense for textual citet, or whether it is more natural to add page reference in the text in that case....

trinker commented 11 years ago

Tested it out. I think you'll want to add pgs <- NULL in there in case the user doesn't provide page numbers as in:

citep <- function(x, ..., 
                  format_inline_fn = format_authoryear_p, 
                  inline_format = authoryear_p,
                  page = NULL){
  text <- citet(x, ..., 
                format_inline_fn = format_inline_fn,
                inline_format = inline_format) 
  pgs <- NULL    #add this line
  if(!is.null(page)){
    pgs <- ifelse(grepl("-", page), "pp.", "p.")
    pgs <- paste(",", pgs, page)
  }
  paste("(", text, pgs, ")", sep="", collapse=";")
}

Otherwise I get an error without page numbers.

cboettig commented 11 years ago

Oh good catch, I forgot to check that. Commit fixes this and adds support for citet.

trinker commented 11 years ago

I'm closing this as this works now.

trinker commented 11 years ago

@Carl I am soon ready to push the next version of the reports package to CRAN (waiting on slidify to go to CRAN). I realized that I am relying on the development version of knitcitations for several functions in reports and am curious when you plan to push to CRAN. You last pushed about 2 months ago.

cboettig commented 11 years ago

Thanks for the message, now would probably be a good time to push. (I annoyed CRAN a bit earlier when I added the features in version 0.3 and then followed by some bug-fixes 0.3-2 etc..) Looking over this I should put the open issues into milestones at some point to figure out what to tackle next. If there's anything you like to see prioritized (existing issue or not) feel free to leave a comment.

On Tue, May 21, 2013 at 9:43 PM, Tyler Rinker notifications@github.comwrote:

@Carl https://github.com/Carl I am soon ready to push the next version of the reports package to CRAN (waiting on slidify to go to CRAN). I realized that I am relying on the development version of knitcitations for several functions in reports and am curious when you plan to push to CRAN. You last pushed about 2 months ago.

— Reply to this email directly or view it on GitHubhttps://github.com/cboettig/knitcitations/issues/32#issuecomment-18257219 .

Carl Boettiger UC Santa Cruz http://carlboettiger.info/