cboettig / knitcitations

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

Using numeric citations removes the final bibliography list #70

Closed lmmx closed 9 years ago

lmmx commented 9 years ago

After setting cite_options(cite.style="numeric"), #26 , I get numbered citations as desired, but subsequently no final references list is produced at the end of the document. I tried changing cite.style back to default "authoryear" at the end of my document but the first setting overrides it.

Is it possible to get this?

citepcomma <- function (x, ...) { bib <- do.call(c, lapply(x, knit_cite, ...)) citation_format <- getOption("citation_format", "text") if (citation_format == "pandoc") paste0("(", paste0("@", sapply(bib, function(b) b$key), collapse = ", "), ")") else Citep(bib, ...) }

citepc(c("10.1038/nrc3690","10.1126/science.7529940")) Error in match.fun(FUN) : object 'knit_cite' not found

cboettig commented 9 years ago

Thanks for the report. Are you sure you're setting cite_options at the top of the file? It seems to work for me:

> library(knitcitations)
citet> cite_options(cite.style='numeric')
> citep(c("10.1038/nrc3690","10.1126/science.7529940"))
[1] "[1; 2]"
> bibliography()
[1] T. L. Nero, C. J. Morton, J. K. Holien, J. Wielens, et al.
“Oncogenic protein interfaces: small molecules, big challenges”. In:
_Nat Rev Cancer_ 14.4 (Mar. 2014), pp. 248-262. DOI: 10.1038/nrc3690.
<URL: http://dx.doi.org/10.1038/nrc3690>.

[2] T. Clackson and J. Wells. “A hot spot of binding energy in a
hormone-receptor interface”. In: _Science_ 267.5196 (Jan. 1995), pp.
383-386. DOI: 10.1126/science.7529940. <URL:
http://dx.doi.org/10.1126/science.7529940>.
> 

You're correct that toggling the cite.style at the end will make an empty bibliography, because no citations have been recorded in the new cite.style.

You can change the punctuation (see ?BibOptions, it just isn't documented). Try:

cite_options(cite.style='numeric', bibpunct=c('(', ')', '(', ')', ',', ','))
citep(c("10.1038/nrc3690","10.1126/science.7529940"))

bibpunct is a bit crude at the moment: the first two are the delimiters for the author-year format (parentheses by default), the second two the delimiters for the numeric format (square braces by default, which I change above to parentheses), then the separation for the numerics (changed from semicolon to comma), and then the year separator).

Open to better ideas on how to do that. sorry for the slow reply, have been traveling.

cboettig commented 9 years ago

I think this issue is resolved by bibpunct and the order of operations, allbeit perhaps not ideally. So I will close for now, though PR on alternative approaches always welcome.

sobradob commented 8 years ago

Hi,

I am having similar issues.

{r}
summary(cars)
library(knitcitations)
  library(bibtex)
cite_options(cite.style="numeric")

This gives me numeric citations but no reference whilst putting the code below gives me a reference but no numeric citations.

{r}
summary(cars)
library(knitcitations)
  library(bibtex)
cite_options(citation_format = "pandoc", check.entries=FALSE, cite.style="numeric")

errExample.txt

Its my first attempt at using the package, so I might be doing something wrong.

cboettig commented 8 years ago

thanks, I'll try and take a look soon