"Debug location is approximate because the source is not available" in R 4.0.0 + RStudio
Asked Answered
T

1

9

I've updated to R 4.0.0 and RStudio version 1.2.5042.

I'm developing a package and I've regularly used the following workflow:

  1. Build the package from within RStudio by clicking the "Install & Restart" button (including the --with-keep.source R CMD INSTALL option).
  2. Set a breakpoint in the .R file of the function I want to debug.
  3. Call the function and wait for the debugger to stop exactly where I set the breakpoint.

This used to work nicely. Now, however, I always get:

Debug location is approximate because the source is not available

This is annyoing because I can still debug, but I'm not in the actual function anymore.

Any hints/ideas why this is?

Edit (11.05.2020)

It seems like this is an issue with RStudio and R 4.0.0. Here is why I think so. I used another machine running Windows 10 and did the following steps (in this order; should be reproducible for Windows users). At the outset I had R 3.6.1 and RStudio 1.2.5042 installed (at the time of writing 1.2.5042 was the current version; tried also with the preview version 1.3.957 of RStudio).

  1. Clone the package I'm developing from Github:

    git clone "https://github.com/M-E-Rademaker/cSEM"
    
  2. Go to the package root and open cSEM.Rproj

  3. Run devtools::install_github("M-E-Rademaker/cSEM") to automatically install the package and download all packages that cSEM depends on.
  4. In RStudio: click on "Build" install and "Install and Restart"
  5. Now naviagte to a source file. For example: R/00_csem.R and set a breakpoint in e.g. line 321.
  6. Now run the following piece of code:

    model <- "
    # Structural model
    eta2 ~ eta1
    eta3 ~ eta1 + eta2
    
    # Measurement
    eta1 =~ y11 + y12 + y13
    eta2 =~ y21 + y22 + y23
    eta3 =~ y31 + y32 + y33
    "
    
    res <- csem(threecommonfactors, model)
    

    The debugger should start and take you right to line 321. You should be able to alter code and you should NOT get the "debug-location-is-approximate-because-the-source-is-not-availabe" warning IF you are on an R version below 4.0.0.

  7. Go to R/00_csem.R and remove the breakpoint in line 321
  8. Close Rstudio and update R to 4.0.0 (using e.g. installr::updateR())
  9. IMPORTANT: also get the newest version of Rtools and follow the steps on the website concerning the part where you need to add rtools to PATH. https://cran.r-project.org/bin/windows/Rtools/
  10. Since you need to reinstall all packages: open cSEM.Rproj again; run install.packages("devtools")
  11. Now repeat steps 3, 4, 5, and 6.
  12. The debugger should stop at line 321 again, however, this time you do get the "debug-location-is-approximate-because-the-source-is-not-availabe" warning.

Why is that? Any ideas/hints/suggestions are welcome!!

Other things I tried:

  • Deleting the package from win-library and reinstalling
  • Reinstalling the package from GitHub using devtools::install_github()
  • Checked package root
  • Updated all dependency packages
  • Repeated the procedure on different machines
  • I develop another package which you can clone from GitHub here: https://github.com/M-E-Rademaker/cSEM.DGP. You can run the same procedure with this package, however, here I dont get the warning when using 4.0.0...which is extremly odd I think.
Twain answered 4/5, 2020 at 13:19 Comment(3)
So when you switch back to a R 3.x version, the issue does not occur?Magnetomotive
I have tried it on another machine with 3.6.1; there it works fine.Twain
I think the problem must be that somehow there is no source available althought when I click "Install and Restart" the log clearly shows that the source is build...I'm puzzledTwain
Z
8

I investigated this using your package and discovered that what you're seeing here is a bug fairly deep in the RStudio / R interface, caused by some subtle changes R made in R 4.0 around source references.

The problem happens whenever there's a backslash (\) in a function's code. When that happens, R is escaping it, which causes RStudio to think that the copy of the function you're looking at is different than the one in the file, which in turn causes it to show you a copy in a code browser instead of opening the file itself.

Since your csem() function contains a backslash it triggers the issue. I've written this up on our issue tracker here:

https://github.com/rstudio/rstudio/issues/6854

Zoubek answered 11/5, 2020 at 22:32 Comment(7)
Dear Jonathan, thanks for tracking down the bug and for writting it up on the issue tracker!Twain
@Jonathan: Any ideas if this has been fixed in the latest edition of RStudio or still outstanding? I am using RStudio Version 1.4.1106 and still facing this issue.Keciakeck
@Keciakeck the same version, I am facing this problem too!Telegraph
@Telegraph #67528524Keciakeck
@Keciakeck I don't have a browser() in my R scriptTelegraph
I only have a forward slash in my function, and I also have this issue... . No backward slashes present... .Lavona
I don't have any backslash in the function and receive this message. I thought it was linked to trying to re-run the Shiny app before saving the changes outside of run-time environment but that is not the case.Always

© 2022 - 2024 — McMap. All rights reserved.