crsh / citr

RStudio Addin to Insert Markdown Citations
Other
407 stars 46 forks source link

insert_citation_cli() #54

Closed Robinlovelace closed 4 years ago

Robinlovelace commented 4 years ago

When using citr in an environment that does not support shiny, it's hard to insert citations. I think a command line interface version of the excellent insert_citation() function would be possible and useful.

Describe the solution you'd like

A function for inserting citations that does not rely on shiny.

Describe alternatives you've considered

Currently I open the bib file(s) or Zotero and copy paste. There must be a better way!

crsh commented 4 years ago

Hi Robin, have you looked at citr::md_cite()? If this is what you are looking for, I admit the function name could be more descriptive. I could add insert_citation_cli() or insert_citation_console() as an alias.

Robinlovelace commented 4 years ago

I have but that still doesn't help if you're in a shell on a remote server.

crsh commented 4 years ago

Hmm, I'm not sure I understand your setup and/or the problem. That function does not rely on either Zotero or shiny. It returns the citation key to the R console. Is this where you are looking for a solution? An automatic insertion into an R Markdown file?

Robinlovelace commented 4 years ago

Aha I see this:

citr::md_cite(x = "geocomp", bib_file = "vignettes/references.bib")
     Lovelace, Nowosad, & Muenchow (2019). Geocomputation with R.  

[1] "[@lovelace_geocomputation_2019]"

That is news to me. Great job, and resolves this issue. My only additional comment would be that it could be useful to output the citation in alternative formats, e.g. as a RefManageR::as.BibEntry() object, or character strings representing .bib files. I could imagine a format_out argument could do that but that may be mission creep. I'm thinking about the situation where you want to search for a citation in a big .bib file and then append the result to a smaller one manually.

crsh commented 4 years ago

Great. Indeed, this seems a little beyond the scope of the package. However, a simple way to achieve the same goal would be to simply work off of a copy of the complete bibliography file and, once all desired citations have been inserted, use tidy_bib_file() to remove everything that's not needed.

Robinlovelace commented 4 years ago

Thanks for quick-fire follow up on this, definitely answers the question.