JuliaInterpreter.jl icon indicating copy to clipboard operation
JuliaInterpreter.jl copied to clipboard

Debugger cannot handle calls to R made using RCall

Open PGS62 opened this issue 5 years ago • 7 comments

Debugger fails when attempting to debug calls to RCall.reval as described in this post I made today on Julia Discourse. It was suggested that I raise it as an issue here.

Here is the example posted:

using RCall
function test()
    reval("1+1")
end

julia> test()
RObject{RealSxp}
[1] 2


julia> @enter test()
In test() at d:\Philip\Source\script\Julia\JSource\xccyHWhooks.jl:373
 372  function test()
>373      reval("1+1")
 374  end

About to run: (RCall.reval)("1+1")
1|debug> n
ERROR: MethodError: no method matching iterate(::Type{Ptr{RCall.SxpHead}})
Closest candidates are:
  iterate(::Core.SimpleVector) at essentials.jl:568
  iterate(::Core.SimpleVector, ::Any) at essentials.jl:568
  iterate(::ExponentialBackOff) at error.jl:199
  ...
Stacktrace:
 [1] safe_parseVector(::Ptr{StrSxp}, ::Base.RefValue{Int32}, ::Ptr{NilSxp}) at C:\Users\Philip\.julia\packages\RCall\g7dhB\src\eval.jl:6
 [2] rparse_p(::Ptr{StrSxp}, ::Ptr{NilSxp}) at C:\Users\Philip\.julia\packages\RCall\g7dhB\src\eval.jl:49
 [3] rparse_p(::String, ::Ptr{NilSxp}) at C:\Users\Philip\.julia\packages\RCall\g7dhB\src\eval.jl:70
 [4] rparse_p(::String) at C:\Users\Philip\.julia\packages\RCall\g7dhB\src\eval.jl:70
 [5] reval(::String, ::RObject{EnvSxp}) at C:\Users\Philip\.julia\packages\RCall\g7dhB\src\eval.jl:132
 [6] reval(::String) at C:\Users\Philip\.julia\packages\RCall\g7dhB\src\eval.jl:132
 [7] test() at d:\Philip\Source\script\Julia\JSource\xccyHWhooks.jl:373

PGS62 avatar Oct 01 '19 15:10 PGS62

This is probably a dup of #285. I can't figure out how to resolve the module-hygeine issues in the potential fix, #290. Maybe we need to disable building compiled ccall etc for parametric functions?

timholy avatar Oct 02 '19 06:10 timholy

Maybe we need to disable building compiled ccall etc for parametric functions?

Is there any way we can detect the bad case and disable compilation only in those cases?

KristofferC avatar Oct 02 '19 07:10 KristofferC

Maybe RetType.hasfreetypevars && return nothing? Haven't tested it.

timholy avatar Oct 02 '19 07:10 timholy

Might be fixed by #290. I can't install RCall properly so I can't easily check.

timholy avatar Oct 03 '19 16:10 timholy

#290 is merged now so please try the master branch and close this if it is fixed.

timholy avatar Oct 03 '19 18:10 timholy

I think the problem is not fixed. To reach that conclusion I did the following:

  1. Verified that I could replicate the problem I reported at the start of this thread.
  2. Ran update at the package prompt.
  3. Also ran add JuliaInterpreter. Previously JuliaInterpreter was not listed by a call to status even though Debugger was listed and I understand that Debugger uses JuliaInterpreter.
  4. Noted that status now listed JuliaInterpreter as version v0.7.4 which is the version released October 3.
  5. Re-ran the test, but saw the same failure - see below.
using RCall
function test()
    reval("1+1")
end

julia> test()
RObject{RealSxp}
[1] 2


julia> @enter test()
In test() at d:\Philip\Source\script\Julia\JSource\adhoc2.jl:22
 21  function test()
>22      reval("1+1")
 23  end

About to run: (RCall.reval)("1+1")
1|debug> n
ERROR: MethodError: no method matching iterate(::Type{Ptr{RCall.SxpHead}})
Closest candidates are:
  iterate(::Core.SimpleVector) at essentials.jl:568
  iterate(::Core.SimpleVector, ::Any) at essentials.jl:568
  iterate(::ExponentialBackOff) at error.jl:199
  ...
Stacktrace:
 [1] safe_parseVector(::Ptr{StrSxp}, ::Base.RefValue{Int32}, ::Ptr{NilSxp}) at C:\Users\Philip\.julia\packages\RCall\g7dhB\src\eval.jl:6
 [2] rparse_p(::Ptr{StrSxp}, ::Ptr{NilSxp}) at C:\Users\Philip\.julia\packages\RCall\g7dhB\src\eval.jl:49
 [3] rparse_p(::String, ::Ptr{NilSxp}) at C:\Users\Philip\.julia\packages\RCall\g7dhB\src\eval.jl:70
 [4] rparse_p(::String) at C:\Users\Philip\.julia\packages\RCall\g7dhB\src\eval.jl:70
 [5] reval(::String, ::RObject{EnvSxp}) at C:\Users\Philip\.julia\packages\RCall\g7dhB\src\eval.jl:132
 [6] reval(::String) at C:\Users\Philip\.julia\packages\RCall\g7dhB\src\eval.jl:132
 [7] test() at d:\Philip\Source\script\Julia\JSource\adhoc2.jl:22


julia> versioninfo()
Julia Version 1.1.1
Commit 55e36cc308 (2019-05-16 04:10 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = "C:\Users\Philip\AppData\Local\Programs\Microsoft VS Code\Code.exe"

(v1.1) pkg> status
    Status `C:\Users\Philip\.julia\environments\v1.1\Project.toml`
  [6e4b80f9] BenchmarkTools v0.4.3
  [9a962f9c] DataAPI v1.1.0
  [82cc6244] DataInterpolations v1.1.1
  [31a5f54b] Debugger v0.6.2
  [39dd38d3] Dierckx v0.4.1
  [31c24e10] Distributions v0.21.3
  [a98d9a8b] Interpolations v0.12.2
  [682c06a0] JSON v0.21.0
  [aa1ae85d] JuliaInterpreter v0.7.4
  [2774e3e8] NLsolve v4.1.0
  [86f7a689] NamedArrays v0.9.3
  [91a5bcdd] Plots v0.26.3
  [6f49c342] RCall v0.13.4
  [295af30f] Revise v2.2.0
  [f2b01f46] Roots v0.8.3
  [ed01d8cd] Sobol v1.3.0
  [bd369af6] Tables v0.2.11
  [9ff05d80] TickTock v1.0.0
  [44d3d7a6] Weave v0.9.1
  [8bb1440f] DelimitedFiles

PGS62 avatar Oct 04 '19 17:10 PGS62

Just wanted to second that I also believe that this problem is not fixed in VScode. Strangely enough RCall works for me in the VS code debug console but not when called in a script in debugger mode. For me the trackback also always leads back to the rparse_p function, as in your example.

When just testing using the simple example import Pkg; Pkg.add("RCall") Pkg.build("RCall") using RCall R"rnorm(10)"

I get the trace back:

TypeError: in typeassert, expected Core.SimpleVector, got a value of type Int64

Stacktrace:
 [1] protect(p::Ptr{StrSxp})
   @ RCall [~/.julia/packages/RCall/6kphM/src/types.jl:269]()
 [2] rparse_p(st::Ptr{StrSxp}, sf::Ptr{NilSxp})
   @ RCall [~/.julia/packages/RCall/6kphM/src/eval.jl:49]()
 [3] rparse_p(st::String, sf::Ptr{NilSxp})
   @ RCall [~/.julia/packages/RCall/6kphM/src/eval.jl:74]()
 [4] rparse_p(st::String)
   @ RCall [~/.julia/packages/RCall/6kphM/src/eval.jl:74]()
 [5] reval(str::String, env::RObject{EnvSxp})
   @ RCall [~/.julia/packages/RCall/6kphM/src/eval.jl:136]()
 [6] top-level scope
   @ [~/Documents/ARGTools/plot_tester.jl:5]()

However, this works via the debug console, jupyter notebooks and when run via the command line.

anna-parker avatar Apr 06 '22 09:04 anna-parker