Graphics support in Renjin 0.9.2628

122 views
Skip to first unread message

Alexander Bertram

unread,
Apr 25, 2018, 3:43:55 AM4/25/18
to renji...@googlegroups.com, Simon Urbanek
Hi all,
Just a quick note to let you know that with build 0.9.2628, Renjin now supports the grDevices, graphics, and grid packages.

You can see examples of output from the ggplot2 examples here:

This work is a result of improvements to our gcc-bridge compiler which allows us to compile and transform the R graphics and grid packages without modification, and an integration of R grDevices C code with Simon Urbanek's JavaGD device driver, which provides a bridge between the R graphics device API and the Java Graphics2D API, allowing us to match the expressiveness of R's high level graphics API with the platform-independence and robustness of the ecosystem of low-level JVM graphics devices.

So far, I've only wired up devices for png, svg, and and interactive screen device that Simon wrote, but I'd like to implement a pdf device based on Apache PDFBox and the rest of the raster image formats in the coming week or so. 

One additional thing  in this release that I'm excited about: it includes a plugin for gcc-bridge that "unglobalizes" global variables in package C code - like that found in the R graphics, grDevices, and grid packages, allowing graphics code to be used concurrently by multiple Renjin sessions running in the same JVM/process.  This means that a web server can safely render plots for parallel requests in the same process, potentially using a single shared copy of the data.

As you can see from the ggplot2 examples, there are still a number of rough edges to work out, so any help opening issues on GitHub, particularly those accompanied by small test cases, would be immensely helpful!

Best,
Alex



Erwan Bocher

unread,
May 2, 2018, 9:22:32 AM5/2/18
to Renjin
Hi Alex,

Great news.

What an impressive work!

Seems there is an issue with  Renjin
Studio 0.9.2643

library("ggplot2")
returns
Error: IOException while loading package org.renjin.cran:ggplot2: IOException while loading package org.renjin.cran:gtable: Could not load package org.renjin:grid

Best regards

Erwan

Erwan Bocher

unread,
May 14, 2018, 2:32:34 PM5/14/18
to Renjin
Hi,

It looks like the second time GGPLOT is initialized.

> library(ggplot2)
Warning messages:
1: In library(ggplot2) :
  Symbol 'arrow' is not defined in package 'org.renjin.cran:ggplot2'
2: In library(ggplot2) :
  Symbol 'alpha' is not defined in package 'org.renjin.cran:ggplot2'
3: In library(ggplot2) :
  Symbol 'unit' is not defined in package 'org.renjin.cran:ggplot2'

But I'm not able to create a  bar plot

df <- data.frame(dose=c("D0.5", "D1", "D2"),
                len=c(4.2, 10, 29.5))

p<-ggplot(data=df, aes(x=dose, y=len)) +
  geom_bar(stat="identity")
Error: Invalid argument:
    +(list, environment)
    Expected:
    +(Complex, Complex)
    +(Vector)
    +(integer, integer)
    +(double, double)

May I forgot something ?

Best regards

Per Nyfelt

unread,
Dec 19, 2018, 12:11:50 PM12/19/18
to Renjin
Hi Alex,

Would you mind explaining how this works? How do I use the graphics capabilities with the ScriptEngine?

Best regards,
Per

Bertram, Alexander

unread,
Dec 20, 2018, 3:40:02 AM12/20/18
to renji...@googlegroups.com
Hi Per,
Mostly this should work in the same way as in GNU R. For example, the following will write a simple plot to disk:

png(filename="plot.png")
plot(1:12)
dev.off()

You can evalute this code with the scriptEngine and the result should be the same.

Renjin should also make it possible to (more) easily implement your own graphics device, for example for a different file format. Take a look at org.renjin.grDevices.FileDevice and org.renjin.grDevices.AwtDevice as examples.

Best,
Alex



--
You received this message because you are subscribed to the Google Groups "Renjin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to renjin-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Alex Bertram
Technical Director
bedatadriven

Web: http://bedatadriven.com
Tel. Nederlands: +31(0)647205388
Skype: akbertram

Per Nyfelt

unread,
Dec 20, 2018, 4:20:23 AM12/20/18
to Renjin
Thank you! I'll look at the code and see if I can figure something out for java fx.

if I follow your example in the Renjin Studio I get exceptions:

Renjin 0.9.2715
Copyright (C) 2018 The R Foundation for Statistical Computing
Copyright (C) 2018 BeDataDriven
> png(filename="plot.png")
Error: Exception calling col2rgb : null
> plot(1:12)
Error: Exception calling list(name = devholdflush, address = org.renjin.sexp.ExternalPtr@69bbe08d, numParameters = c(1L)) : null
> dev.off()
Error: Exception calling list(name = devcur, address = org.renjin.sexp.ExternalPtr@6b496f2a, numParameters = c(1L)) : null

Do i need to do something more before to set things up? 

regards,
Per

Bertram, Alexander

unread,
Dec 21, 2018, 5:17:46 AM12/21/18
to renji...@googlegroups.com
Hi Per,
Looks like this is a bug that affects the GUI because of the way it uses threads.

I've opened an issue here:

I have to think about the best way to address this but it shouldn't be a problem.

Best,
Alex

Per Nyfelt

unread,
Dec 21, 2018, 6:21:11 AM12/21/18
to Renjin
Very nice, thanks Alex!

If you are in that code maybe you could consider making it possible for someone outside renjin package structure to implement GDContainer (GDState and GDObject are package private)?

Best regards,
Per

Alexander Bertram

unread,
Dec 29, 2018, 6:29:10 PM12/29/18
to Renjin
@Per and @Erwan, the issue with graphics calls from separate threads (e.g. the Studio GUI) is now fixed in 0.9.2717.

Per, will definitely make these classes public!

Best,
Alex

Per Nyfelt

unread,
Dec 30, 2018, 8:55:04 AM12/30/18
to Renjin
Nice! Works fine thanks!

Erwan Bocher

unread,
Jan 4, 2019, 3:48:32 AM1/4/19
to Renjin
Dear Alex,

First of all I wish you and your team a happy new year.

I tried to run the latest version of Renjin but there seems to be a problem with my file path (note that it works in another place eg /tmp/).
 
See the following trace :

java -jar renjin-studio-0.9.2718-jar-with-dependencies.jar
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Using local repository: /home/ebocher/.m2/repository
Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalStateException: Failed to locate R.home:
    at org.renjin.eval.SessionBuilder.build(SessionBuilder.java:191)
    at org.renjin.studio.StudioSession.<init>(StudioSession.java:45)
    at org.renjin.studio.MainFrame.main(MainFrame.java:84)
Caused by: java.lang.IllegalStateException: Failed to locate R.home:
    at org.renjin.util.FileSystemUtils.homeDirectoryInCoreJar(FileSystemUtils.java:56)
    at org.renjin.eval.Session.<init>(Session.java:143)
    at org.renjin.eval.SessionBuilder.build(SessionBuilder.java:179)
    ... 2 more
Caused by: org.apache.commons.vfs2.FileSystemException: Could not replicate "file:///home/ebocher/Téléchargements/renjin-studio-0.9.2718-jar-with-dependencies.jar" as it does not exist.
    at org.apache.commons.vfs2.provider.AbstractFileSystem.replicateFile(AbstractFileSystem.java:418)
    at org.renjin.eval.vfs.FastJarFileSystem.<init>(FastJarFileSystem.java:55)
    at org.renjin.eval.vfs.FastJarFileProvider.doCreateFileSystem(FastJarFileProvider.java:68)
    at org.apache.commons.vfs2.provider.AbstractLayeredFileProvider.createFileSystem(AbstractLayeredFileProvider.java:89)


I have re-run the script and the same message appears. OS  = Ubuntu 16.04, JVM = OpenJDK 8

Renjin 0.9.2718
Copyright (C) 2019 The R Foundation for Statistical Computing
Copyright (C) 2019 BeDataDriven
> library("ggplot2")

df <- data.frame(dose=c("D0.5", "D1", "D2"),
                len=c(4.2, 10, 29.5))
p<-ggplot(data=df, aes(x=dose, y=len)) +
  geom_bar(stat="identity")
;
Error: IOException while loading package org.renjin.cran:ggplot2: Could not load package org.renjin:grid
> > Error: could not find function 'ggplot'
> Error: could not find function 'ggplot'
> > library("ggplot2")

> df <- data.frame(dose=c("D0.5", "D1", "D2"),
                len=c(4.2, 10, 29.5))
> p<-ggplot(data=df, aes(x=dose, y=len)) +
  geom_bar(stat="identity")
Error: could not find function 'ggplot'
>

Best regards

Erwan

Per Nyfelt

unread,
Jan 4, 2019, 6:59:42 AM1/4/19
to Renjin
Hi Erwan,

Latest version of ggplot2 (3.1.0) requires Rlang 0.3.0.1 which does not build properly.

If you use the ClassPathPackageLoader and specify the dependency to a previous version (3.0.0-b29) which depends on Rlang 0.2.2 your examplecode runs fine

<dependency>
<groupId>org.renjin.cran</groupId>
<artifactId>ggplot2</artifactId>
<version>3.0.0-b29</version>
</dependency>

(Would it not be nice if it was possible to to this with AetherPackageLoader e.g.  library("org.renjin.cran:ggplot2:3.0.0-b29"?)

Best regards,
Per

Bertram, Alexander

unread,
Jan 11, 2019, 3:56:54 AM1/11/19
to renji...@googlegroups.com
Hi Erwan,
The issue with non-ASCII characters in resource paths has been resolved in the latest release. (And I have renamed my working directory to réñjin to catch such problems in the future ;-)

Per,
Thanks for the tip on ggplot2. I will take a look at Rlang next week, time permitting. 

I agree that loading versioned libraries is super useful. What is a bit challenging is that not all PackageLoader implementations should be expected to support versioned package loading. For example, if you are running Renjin embedded on a webserver, you are stuck with the version of the package shipped with the WAR, and that's a good thing. Maybe I'm overthinking it though-  perhaps just a warning if the requested version can't be honored?

Best,
Alex




Alexander Bertram
Technical Director
BeDataDriven BV

Erwan Bocher

unread,
Jan 11, 2019, 7:39:40 AM1/11/19
to Renjin


Le vendredi 11 janvier 2019 09:56:54 UTC+1, Alexander Bertram a écrit :
Hi Erwan,
The issue with non-ASCII characters in resource paths has been resolved in the latest release. (And I have renamed my working directory to réñjin to catch such problems in the future ;-)
@Alex,

Thanks I will look on it.

Per,
Thanks for the tip on ggplot2. I will take a look at Rlang next week, time permitting. 

+1

and thanks @Per for the trick
Best

Per Nyfelt

unread,
Jan 12, 2019, 7:55:20 AM1/12/19
to Renjin
Yes, this would not make sense for ClasspathPackageLoader. I have added some comments to the issue at github: https://github.com/bedatadriven/renjin/issues/433.

Best regards,
Per
Reply all
Reply to author
Forward
0 new messages