Strange error when using RStudio addin with rstudioapi::setCursorPosition for the first time in a given session

I have been encountering a strange error when using a rstudio addin that I created that I am not sure even how to begin to debug and that would seem to be a rstudioapi bug related to the setCursorPosition function. The addin is the Insert filled data chunk addin of the knitrdata package (driven by the function knitrdata::insert_data_chunk_dialog). The basic functioning of the addin is that you select some options and when you hit the Create Chunk button it inserts a chunk of text into the active document in the RStudio editor. The first and only the first time I use the addin in a given RStudio session, the addin returns an error at the point where it uses rstudioapi::setCursorPosition here. In addition to the fact that this happens only the first time the addin is used (subsequent calls produce no error), the error is strange because it seems to happen in random different places in the process of setting the cursor position (i.e., the traceback is not always the same each time I generate the error even if all the steps I carried out to produce it are the same). It is as if there are several asynchronous operations being carried out, and which one runs into the problem varies slightly from run to run. I have looked at the tracebacks and at least the original setCursorPosition call seems correct (i.e., the position indicated is a valid position in the active document). At the end of this message I include a couple of screenshots showing a couple examples of the errors that can be produced.

The questions I have are:

  1. Is this bug my fault in some way or is this a rstudioapi problem?
  2. Is there a fix or workaround?
  3. If not, how would I go about debugging this problem? As it happens differently each time, I am at a loss of what to do.

For information, my RStudio installation is as follows:

  • Ubuntu 20.04 focal
  • RStudio Version 1.3.1056
  • R 4.0.3
  • rstudioapi 0.13
  • knitrdata 0.6.1

If anyone has some ideas how to fix this, I would much appreciate it.


I was only allowed to add a single screenshot

Another screenshot

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.