oracle / fastr

A high-performance implementation of the R programming language, built on GraalVM.
Other
625 stars 64 forks source link

Raw Vector is turned into `RDoubleVector` where an instance of RIntVector is expected using `pdftools` pdf_render_page #49

Closed NRBPerdijk closed 5 years ago

NRBPerdijk commented 5 years ago

Hello again!

This issue closely resembles issue #46, but this time on graalVM & FastR rc11.

I am still trying to render a page from a pdf with R using pdf_tools and again the FastR code has turned my RAW vector into an RDoubleVector which cannot be cast to RIntVector (see stacktrace at the bottom), eventhough it only contains Integers. (The Array on the Scala side is of type Int.)

Edit: The installed FastR:

ComponentId              Version             Component name
----------------------------------------------------------------
R                        1.0.0-rc11          FastR

R version when running the R command from the graalvm /bin: R version 3.4.3

Stacktrace:

    at com.oracle.truffle.r.nodes.function.FunctionDefinitionNode.execute(FunctionDefinitionNode.java:325)
    at <R>.pdf_render_page(Unknown)
    at <R>.<language>727354707(myRFile.R:linenumber)
    at <R>.eval(Unknown)
    at <R>.<no source>(unknown.r:1)
    at <R>.myRFile
steve-s commented 5 years ago

Hello Nathan,

I've tried on R11 community edition and could not reproduce. Can you share some R code snippet that causes the issue? I've tried:

pdf_render_page(paste0(R.home(), "/doc/NEWS.pdf"))

and that produces a raw vector with the data of the PDF file as expected.

NRBPerdijk commented 5 years ago

Thank you for the reply.

That is interesting, I tried running your code snippet and it failed with the same stacktrace as I posted above. I figured there must be something corrupt about my installation, so I uninstalled fastR using gu, made sure that any trace of R on my system was removed and then deleted and reinstalled my GraalVM installation (rc11).

Sadly, this did not work, I keep running into the same issue. The command line gives me the following versions: JVM:

openjdk version "1.8.0_192"
OpenJDK Runtime Environment (build 1.8.0_192-20181024123616.buildslave.jdk8u-src-tar--b12)
GraalVM 1.0.0-rc11 (build 25.192-b12-jvmci-0.53, mixed mode)

FastR:

Filename: https://github.com/oracle/fastr/releases/download/vm-1.0.0-rc11/r-installable-ce-1.0.0-rc11-macos-amd64.jar
Name    : FastR
ID      : R
Version : 1.0.0-rc11
GraalVM : 1.0.0-rc11
Component bundle R cannot be installed
    - The same component FastR (R) is already installed in version 1.0.0-rc11

R: R version 3.5.1 (FastR)

I am a bit at a loss concerning what else I could try or might be missing...

steve-s commented 5 years ago

Sorry I didn't notice this in your first comment:

R version when running the R command from the graalvm /bin: R version 3.4.3

this looks suspicious. FastR never had this version. RC10 should show R 3.4.0 and in RC11 we migrated to R 3.5.1. We'll try reproducing on MacOS. So far I've been trying on Ubuntu box.

NRBPerdijk commented 5 years ago

Yes, I thought that was odd, too. I guess it was interference from a separate R installation. In my second attempt (after explicitly deleting all R on my machine), I did have R 3.5.1, but it was not the problem.

I just found the actual issue by accident:

If you add require("tidyr") or require("dplyr") at the start of the file, you'll replicate the above behavior. If I leave those packages out, it works!

Edit: The above was written in a hurry, so a bit more now that I have some time: Importing tidyr or dplyr in the same file will cause the ClassCastException, even if none of their functionality is actually used. The order of my imports was:

    require("tidyr")
    require("glue")
    require("dplyr")
    require("pdftools")

Commenting out both dplyr and tidyr makes the bug go away, leaving either or both of them in => boom, very misleading exception somewhere in a pdftools function. At least I can now try to work around it, rather than it being a total showstopper. 👍 Let me know if you require any further information and keep up the good work!

steve-s commented 5 years ago

Yes, thank you that was the missing piece, I can now reproduce the issue and we are working on the fix. Thank you for the report and for the help with reproducing.

NRBPerdijk commented 5 years ago

You're welcome, it is an interesting issue!

I have found a few others ways to reproduce, which might be valuable to check whether all the bases have been covered:

All the following will cause the ClassCastException presented above:

I hope this is of further use to you. 👍

steve-s commented 5 years ago

Should be fixed by 6336e09ea0ec3d26b114fb2d8ec1fdf8a349d56c