rstudio / addinexamples

An R package showcasing how RStudio addins can be registered and used.
Other
86 stars 69 forks source link

Error when running examples if no file is open #2

Closed wch closed 8 years ago

wch commented 8 years ago

I (roughly) followed the examples in the documentation, and tried installing and running examples, but without any files open in the editor. When I did that, I got errors like this:

> addinexamples:::findAndReplaceAddin()
Loading required package: shiny

Listening on http://127.0.0.1:5433
Warning: Error in : 'x' should be a list of {range, text} pairs
Stack trace (innermost first):
    46: as.document_selection
    45: rstudioapi::getActiveDocumentContext
    44: <Anonymous>
    43: do.call
    42: server
     3: shiny::runApp
     2: runGadget
     1: addinexamples:::findAndReplaceAddin
Error : 'x' should be a list of {range, text} pairs
kevinushey commented 8 years ago

I think the issue here is with how RStudio detects the active editor:

  1. If the console has focus, defer to the console.
  2. Otherwise, defer to the source window.

In this case, the console has lost focus (as the addin has launched and stolen focus), but there is no alternate editor to use.

That said, I'm not sure what the solution here is, since an interactive addin that needs to work with a document will normally work with a source editor, not the console (although perhaps I'm wrong).

Perhaps what we really need is separate APIs for accessing:

  1. The last-focused source editor (getSourceEditorContext()),
  2. The console (getConsoleEditorContext()),
  3. Fix up getActiveDocumentContext() to track focus, and use the last-focused item.

Thoughts, @jjallaire?

jjallaire commented 8 years ago

Yes, I think we definitely need both of those functions and the tracking behavior that you describe in getActiveDocumentContext.

BTW, I wonder if that function should be renamed getActiveEditorContext in light of the names of the other two functions?

On Fri, Jan 22, 2016 at 5:02 PM, Kevin Ushey notifications@github.com wrote:

I think the issue here is with how RStudio detects the active editor:

  1. If the console has focus, defer to the console.
  2. Otherwise, defer to the source window.

In this case, the console has lost focus (as the addin has launched and stolen focus), but there is no alternate editor to use.

That said, I'm not sure what the solution here is, since an addin that needs to work with a document will normally work with a source editor, not the console (although perhaps I'm wrong).

Perhaps what we really need is separate APIs for accessing:

  1. The last-focused source editor (getSourceEditorContext()),
  2. The console (getConsoleEditorContext()),
  3. Fix up getActiveDocumentContext() to track focus, and use the last-focused item.

Thoughts, @jjallaire https://github.com/jjallaire?

— Reply to this email directly or view it on GitHub https://github.com/rstudio/addinexamples/issues/2#issuecomment-174066997 .

kevinushey commented 8 years ago

That sounds good to me (we can 'soft-deprecate' the getActiveDocumentContext() function)

koliajaykr commented 7 years ago

I'm trying to use Rstudio add-on for citation but I'm getting this error: citr::insert_citation()

Listening on http://127.0.0.1:7082 Warning in RefManageR::ReadBib(file, check = FALSE) :

F:/thesis-HANDmade-akk/My Library.bib:2212:0 syntax error, unexpected TOKEN_LITERAL, expecting TOKEN_ABBREV or TOKEN_COMMA or TOKEN_KEY Dropping the entry burke_indian_2012 (starting at line 2196) Warning: Error in .BibEntryCheckBibEntry1: A bibentry of bibtype ‘InCollection’ has to specify the field: editor Stack trace (innermost first): 80: .BibEntryCheckBibEntry1 79: $<-.BibEntry 78: $<- 77: MakeKeysUnique 76: c.BibEntry 75: 74: do.call 73: eval 72: eval 71: withProgress 70: 59: bibliography 58: observerFunc 3: shiny::runApp 2: runGadget 1: citr::insert_citation ERROR: [on_request_read] connection reset by peer