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:
--with-keep.source
R CMD INSTALL option)..R
file of the function I want to debug.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?
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).
Clone the package I'm developing from Github:
git clone "https://github.com/M-E-Rademaker/cSEM"
Go to the package root and open cSEM.Rproj
devtools::install_github("M-E-Rademaker/cSEM")
to automatically install the package and download all packages that cSEM
depends on.Build
" install and "Install and Restart
"R/00_csem.R
and set a breakpoint in e.g. line 321.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.
R/00_csem.R
and remove the breakpoint in line 321installr::updateR()
)cSEM.Rproj
again; run install.packages("devtools")
Why is that? Any ideas/hints/suggestions are welcome!!
Other things I tried:
devtools::install_github()
You can do this in RStudio by clicking to the left of the line number in the editor, or by pressing Shift+F9 with your cursor on the desired line. We call this an “editor breakpoint”. Editor breakpoints take effect immediately and don't require you to change your code (unlike browser() breakpoints, below).
Q to stop debug mode, terminate the function, and return to the R prompt.
In the debugger you can run any R command to look at objects in the current environment, modify them and continue executing. Use ls() to determine what objects are available in the current environment. This allows you to see exactly what things you can examine.
R comes with a simple set of debugging tools that RStudio amplifies. You can use these tools to better understand code that produces an error or returns an unexpected result. Usually this will be your own code, but you can also examine the functions in R or one of its packages.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With