crsh / citr

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

RStudio Server - Unsupported? #50

Closed polc1410 closed 5 years ago

polc1410 commented 5 years ago

I use RStudio Server rather than RStudio Desktop. I'm struggling to get citr to work properly

To Reproduce

Install citr (0.3.0 from Cran or Dev from GitHub) on RStudio Server Create .Rmd file with

---
title: "Title"
output: word_document
bibliography: reference.bib
---

Export a bib file and save it to reference.bib Save the .Rmd File

Expected behavior

citr:::insert_citation()

Popup box appears. Should be able to select from list a reference. But no references appear to select...

         falling back to manual path specification.

Listening on http://127.0.0.1:5352

Using:

citr:::insert_citation(bib_file = "reference.bib")

has same result

If the add-in is clicked directly with the Rmd file in context the message about Rmarkdown not being saved is not shown. Listening is still shown. No references shown in popup.

If I enter:

md_cite("authorname 2017", bib_file = "reference.bib")
Authorname, Firstanme (2017). Article Name. Journal Name 

[1] "[@authornamefirstnameArticleName2017]"

So it seems the bib file is accessible - but the pop-up window doesn't seem to be able to access it.

The server does have Zotero Standalone installed - doesn't seem to matter if it is running or not to get the pop-up box to work. With Zotero not running:

> load_betterbiblatex_bib()
Error in curl::curl_fetch_memory(url, handle = handle) : 
  Failed to connect to localhost port 23119: Connection refused

With Zotero running:

> load_betterbiblatex_bib()
Importing 'My Library'...
Error in import_bbt(bib, betterbibtex_url_i, encoding) : 
  argument "encoding" is missing, with no default
load_betterbiblatex_bib(encoding = "UTF-8")
Importing 'My Library'...
Ignoring entry ‘zaveryburhanCouldLogarithmicDosing2011’ (line2) because: 
    The name list field author cannot be parsed

Importing 'DoseBanding'...
Error in .BibEntryCheckBibEntry1(x[[i]]) : 
  zotero-102: A bibentry of bibtype ‘Article’ has to specify the fields: author, title, c("journaltitle", "journal"), c("year", "date")
crsh commented 5 years ago

Thanks for the detailed report, I'll try to look into this as soon as possible.

polc1410 commented 5 years ago

Small update.

I've developed a workaround. But its not perfect. Considering that this is RStudioServer the running of a ZoteroStandalone Application is not particularly likely to be a common use. So perhaps there is more that could be done with my solution to make it elegant!

# Connect to ZoteroBibliography Manager
require(RefManageR)
require(bibtex)
require(tidyverse)

# Login to your Zotero Web Account
# 
# Visit: https://www.zotero.org/settings/keys
# Above the link to create a new API key copy the Your userID for use in API calls is XXXXXX
# copy they key below
#
zoteroUserKey = "XXXXXX"

# Create a new access key (click the link)
# copy the access key below
#
zoteroAccessKey = "YYYYYYYYYY"

# Navigate to the Library or Collection you want to use for referencing.
# e.g. https://www.zotero.org/yourusername/items/collectionKey/ZZZZZZZZ
# 
zoteroCollection="ZZZZZZZZ"

# Download a bib file from zotero server
zotero <- ReadZotero(
                   user = zoteroUserKey, 
                  .params = list(
                         collection = zoteroCollection, 
                         key = zoteroAccessKey
                         )
                   )

# Setup the Bibliography style
#
BibOptions(bib.style="numeric")

# Build a data frame to find the references easier
# This will allow you to view the reference's short names.
# by looking at a data frame called 'refs' and copying the 'key' for the relevant
# title. 
refs <- zotero %>% {
  .$title
} %>%
  bind_rows() %>%
  gather(key = 'key', value = 'title', 1:length(zotero))

# Now write a file containing the bibliography to the current working
# directory.  File will be called 'reference.bib'
#
# And add the following entry (without the # marks) to the YAML header
# ---
# bibliography: reference.bib
# ---

write.bib(zotero, 'reference.bib')

# You can now use [@citation_key_2000] to cite your articles 
# in your markdown.
# Not as simple as using citr directly, but does work on zotero
# and stays up to date as you update your zotero and re-run the code
# 

ideally we might get citr to read the reference.bib file but produce the pop-up and allow you to select the reference - avoiding the refs<- section in the code and manual copy & paste, and easier article searching etc.

crsh commented 5 years ago

So I've been partially able to reproduce the problem. When the focus is on the R Markdown file, it detects the file, but can't load it. When the focus is in the console, the addin resorts back to manual path specification (the error message is somewhat misleading; this is also happens when the focus isn't on an R Markdown file). In this case, the addin successfully reads the file and I can search the references. However, this only works until I first try it with the focus on the R Markdown file (after that I have to restart my R session to be able to read the file). Could you confirm that the last bit is true in your case as well?

Also a quick questions regarding the failing Zotero connection (I don't have Zotero on my RStudio server right now): The missing encoding is a little surprising because it should be taken from the global options. Could you try to reproduce that error and then report the output of getOption("citr.encoding")?

polc1410 commented 5 years ago
> require(citr)
Loading required package: citr
> getOption("citr.encoding")
[1] "UTF-8"
polc1410 commented 5 years ago

So I've been partially able to reproduce the problem. When the focus is on the R Markdown file, it detects the file, but can't load it. When the focus is in the console, the addin resorts back to manual path specification (the error message is somewhat misleading; this is also happens when the focus isn't on an R Markdown file). In this case, the addin successfully reads the file and I can search the references. However, this only works until I first try it with the focus on the R Markdown file (after that I have to restart my R session to be able to read the file). Could you confirm that the last bit is true in your case as well?

Not 100% sure what you wanted me to do! I've tried with the focus on the Rmd file. I get the popup but not file content (curiously the port number changes I notice... so there is a possibility this is a firewall issue... the port could be closed). That happens with a new R session or not and with the Rmd in focus or not.

I'm only seeing "Falling back to manual" if the Rmd isn't saved. That is a bit 'odd' as if you are mid way through typing a document you wouldn't usually click 'save' before clicking insert citation... Even adding a space does the same.

crsh commented 5 years ago

Oh god, this is a little embarrassing. I was only able to reproduce the problem because I specified bibliography: reference.bib in the YAML front matter, but saved the file as references.bib (note the plural s). Now that I have renamed the file, everything works as expected (I haven't looked at your Zotero issue, yet). I'm using the latest citr version available from this repository. Could you provide the output of devtools::session_info()?

no-response[bot] commented 5 years ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.