@gaocegege -- Great -- very interesting look into feasibility with pull/40. The style seems quite readable to me -- although I was a bit confused by class(me) <- append(class(me),"Cell")
Nice decision to use the 2D arrays tutorial as a reference. Another sketch that might be useful to look at as a reference is the "Objects" example -- here implemented in Processing(Java), p5.js(JavaScript), and Processing.py:
Remember that official coding work doesn't start on your project until the start of GSOC at the end of the month, and this isn't a milestone on your proposal -- we are just discussing if it would be feasible for Processing.R to support advanced sketches at some point in the future.
For forum members checking out this thread who aren't following along on github, @gaocegege is doing amazing work there on Processing.R. Here is an example of a 3D sketch that is already running in the installable Processing.R mode under development.
PI <- 3.1415
settings <- function()
{
processing$size(500, 500, "processing.opengl.PGraphics3D")
}
setup <- function()
{
processing$colorMode(as.integer(1), 1)
processing$frameRate(24)
}
draw <- function()
{
frames <- 24 * 3
t <- processing$frameCount() / frames
processing$background(1)
processing$perspective(0.5, 1, 0.01, 100)
processing$camera(
0, 0, 25 + sin(PI * 2 * t) * 3,
0, 0, 0,
0, 1, 0
)
processing$rotateX(-0.5 - 0.05 * sin(PI * 4 * t))
processing$rotateY(-0.5 - 0.05 * cos(PI * 2 * t))
columns <- 8
for (ix in 1:columns - 1)
{
x <- ix - 0.5 * columns + 0.5
for (iy in 1:columns - 1)
{
y <- iy - 0.5 * columns + 0.5
for (iz in 1:columns - 1)
{
z <- iz - 0.5 * columns + 0.5
d <- sqrt(x * x + y * y + z * z)
s <- abs(sin(d - t * 4 * PI))
processing$pushMatrix()
processing$translate(x, z, y)
processing$box(s)
processing$popMatrix()
}
}
}
}
You cannot mix in Java-style for loops or ternary operators because Processing.R is written in almost pure R (there will probably be a pre-processor). It is transpiled by rejin from R into Java, (much like Processing.py is transpiled by Jython from Python into Java).
However, if you use an R-style for-in loop and R-style ifelsefor the ternary, this example based on yours draws a line graph in Processing.R using data.frame:
x = c(10, 20, 30, 40, 50, 60, 70, 80, 90)
y = c(22, 3, 45, 0, 15, 77, 63, 45, 90)
y = height - y
s = c("aa", "bb", "cc")
b = c(TRUE, FALSE, TRUE)
df = data.frame(x, y, s, b)
for(i in 2:length(df$x)){
processing$stroke(ifelse(df$b, 255, 0))
processing$line(df$x[i],df$y[i],df$x[i-1],df$y[i-1])
}
stdout$print(df)
Processing.R will be starting as a Google Summer of Code project at the end of the month -- it is already under active development by @gaocegege.
You cannot install the Processing.R mode through the lib manager, yet -- PDE integration is very alpha -- but there are instructions for building the mode with ant and installing it here:
@kfrajer -- yes, all vector operations etc. are supported by renjin, because it is an R transpiler -- It runs R. My demo sketch above contains an example: y = height - y acts on the vector y.
I don't believe that R's plot() will work -- it is for drawing to its own screen, and Processing.R instead draws to the Processing canvas by mapping drawing calls like ellipse() and box() etc. to the Processing(Java) API. Since renjin is running on JVM it can use native R idioms for data and also use the Processing core.jar and pde.jar directly for graphics.
Developing an R-like plot() for Processing.R is outside the scope of the current project. At some point in the future Processing.R should be able to work with some existing Java graphing libraries -- like grafica -- http://jagracar.com/grafica.php . For example, Processing.py does Java library integration with add_library('grafica'); examples are in Contributed Libraries With Python.
...however, @gaocegege probably knows more about R's plot() and how interaction with libraries might work than I do!
frameCount is a variable in Processing, but renjin bounds the java variable into R scope as a constant. Then I define the variable as a getter in Java.
It could be avoided if the pre-processor is imported.
Actually, I am not sure how to support the built-in functions such as plot. I will try to know the logic in renjin. But I think ".pde" files aren't valid ".java" files. is also the principle of Processing.R. If plot is supported in Processing.R, Processing should be the first class, not R, which means that we should implement plot in Processing, not use R function.
And, before implementing new features in Processing, the mode should look (someday, in the future) at how renjin imports Java libraries -- no need to reinvent the wheel of plotting.
The experience of the Processing.py mode with Java-libraries-in-Jython seems to have been this: Some Processing(Java) libraries worked without needing changes. Others required minor changes. Others needed a full separate version of the library or would not work at all.
Now Processing.R has released a new version v1.0.3. In this version most of built-in functions in Processing are supported in Processing.R. And we are building the references documentation for new users: https://processing-r.github.io/Processing.R-docs/.
# sketch based on the grafica library example: DefaultPlot.pde
settings <- function() {
# Please install the grafica library before you run the example.
importLibrary("grafica")
size(500, 350)
}
setup <- function() {
background(150)
nPoints <- 100
## expected constructor, doesn't work points <- GPointsArray$new(nPoints)
points <- GPointsArray$new()
for (i in 1:nPoints) {
points$add(i, 10 * noise(0.1 * i))
}
## Create a new plot and set its position on the screen
plot <- GPlot$new(processing)
plot$setPos(25, 25)
## or all in one go plot <- GPlot$new(processing, 25, 25)
## Set the plot title and the axis labels
plot$setTitleText("A very simple example")
plot$getXAxis()$setAxisLabelText("x axis")
plot$getYAxis()$setAxisLabelText("y axis")
## Add the points
plot$setPoints(points)
## Draw it!
plot$defaultDraw()
}
Processing.R is a new mode for PDE, but now the users have to install the mode manually. Then I think maybe it is time to ask how to add Processing.R into PDE contribution manager and what should I do for the integration.
I'd appreciate it if someone could give me some suggestions or requirements @shiffman@jeremydouglass
So excited to see the progress! For getting it into the contribution manager, you should contact @prisonerjohn. It's mostly the same process as with libraries and all the info is here:
Hey, gaocegege, than you for making grafica work in R!
I have to give it a try :)
Do you see why the lib could be useful there? I created grafica because processing was missing a simple way to plot data, but R is basically designed for that.
Ah, ok. So one would use grafica in R when one needs to use a processing lib that is not available in R, use the R statistical libs and plot things at the same time.
Yeah, animation in R is not well supported but it is good in Processing. Statistic computing is not well in Java and Processing but R is one of the best tools. Processing.R wants to combine these two things.
So one would use grafica in R when one needs to use a processing lib that is not available in R, use the R statistical libs and plot things at the same time.
That is correct. For example, in Processing.R you could embed a graphica plot in a P3D sketch that uses Processing libraries like peasycam and Processing built-ins like interactive keyboard control -- but is visualizing the contents of matrices / data frames using native R statistical processing.
Another reason to use grafica here is that, while Processing.R combines the strengths of importing Processing libraries and R packages, the support for R packages is extremely limited, and it can only run "pure" R code on its JVM-based R interpreter, renjin. That means plot() / ggplot don't work in Processing.R, because they aren't written in pure native R code. Hence: grafica!
Unfortunately, ggplot2 and most other graphics packages do not currently work with renjin. This is due to compatibility issues arising from trying to compile the original source code of some packages into java bytecode. https://stackoverflow.com/a/41417220
We have some discussions about when to migrate Processing.R to the foundation before. These days I have no enough time to maintain the project and I think it is better to contribute it to the foundation and students from GSoC may have some new ideas about the mode.
We migrated the project to github.com/processing-r/Processing.R. And I have no time to maintain it because of some personal reasons. If anyone is interested in this project, feel free to contribute. And welcome to apply GSoC based on it.
Comments
As for p5.js, I think it does not fit R well. But I will have a try.
So my work now in the PR is find a way to store objects in R structures and try other OO ways such as S4 and RN.
@gaocegege -- Great -- very interesting look into feasibility with pull/40. The style seems quite readable to me -- although I was a bit confused by
class(me) <- append(class(me),"Cell")
Nice decision to use the 2D arrays tutorial as a reference. Another sketch that might be useful to look at as a reference is the "Objects" example -- here implemented in Processing(Java), p5.js(JavaScript), and Processing.py:
Remember that official coding work doesn't start on your project until the start of GSOC at the end of the month, and this isn't a milestone on your proposal -- we are just discussing if it would be feasible for Processing.R to support advanced sketches at some point in the future.
@jeremydouglass
class(me) <- append(class(me),"Cell")
is a trick to S3, which adds the "Cell" as the class name.And, FYI, the PR is done:
Renjin supports S3 natively :)
We could discuss about the example further in GitHub :)
For forum members checking out this thread who aren't following along on github, @gaocegege is doing amazing work there on Processing.R. Here is an example of a 3D sketch that is already running in the installable Processing.R mode under development.
@gaocegege
I haven't been able to follow the GitHub discussion. Just a quick question: Is it possible to use = instead of <- ?
Another ?.... Do you have an example working with a data.frame? For example:
Then do something like this: plot df$n vs. df$m. How would you do it?
Kf
@kfrajer --
re:
=
: renjin is a full R interpreter for JVM, so assignment operators (=
<-
<<-
etc.) work as normal. You can use=
for most things.re:
data.frame
: This runs fine in Processing.R:Output:
Could you say more what you mean about plotting?
@jeremydouglass: Using processing, could I use point() or work on my own for loop to draw lines? I want to do:
How do I get p.R ? Through the lib manager?
Kf
You cannot mix in Java-style for loops or ternary operators because Processing.R is written in almost pure R (there will probably be a pre-processor). It is transpiled by rejin from R into Java, (much like Processing.py is transpiled by Jython from Python into Java).
However, if you use an R-style
for-in
loop and R-styleifelse
for the ternary, this example based on yours draws a line graph in Processing.R using data.frame:Processing.R will be starting as a Google Summer of Code project at the end of the month -- it is already under active development by @gaocegege.
You cannot install the Processing.R mode through the lib manager, yet -- PDE integration is very alpha -- but there are instructions for building the mode with ant and installing it here:
I can see now how R in processing works. So one could do vector operations similar to one do in R like
df$x=df$x*10
?The previous code could be plotted in R using:
plot(df$x,df$y,type="b",col=as.numeric(df$b)+1)
Would a plot functionality similar to what comes with R be available in the Processing.R mode?
Kf
@kfrajer -- yes, all vector operations etc. are supported by renjin, because it is an R transpiler -- It runs R. My demo sketch above contains an example:
y = height - y
acts on the vector y.I don't believe that R's
plot()
will work -- it is for drawing to its own screen, and Processing.R instead draws to the Processing canvas by mapping drawing calls likeellipse()
andbox()
etc. to the Processing(Java) API. Since renjin is running on JVM it can use native R idioms for data and also use the Processing core.jar and pde.jar directly for graphics.Developing an R-like
plot()
for Processing.R is outside the scope of the current project. At some point in the future Processing.R should be able to work with some existing Java graphing libraries -- like grafica -- http://jagracar.com/grafica.php . For example, Processing.py does Java library integration withadd_library('grafica')
; examples are in Contributed Libraries With Python....however, @gaocegege probably knows more about R's
plot()
and how interaction with libraries might work than I do!Hi, all
There is a trade off in this example:
processing$frameCount()
frameCount is a variable in Processing, but renjin bounds the java variable into R scope as a constant. Then I define the variable as a getter in Java.
It could be avoided if the pre-processor is imported.
Actually, I am not sure how to support the built-in functions such as
plot
. I will try to know the logic in renjin. But I think".pde" files aren't valid ".java" files.
is also the principle of Processing.R. If plot is supported in Processing.R, Processing should be the first class, not R, which means that we should implement plot in Processing, not use R function.Great summary!
And, before implementing new features in Processing, the mode should look (someday, in the future) at how renjin imports Java libraries -- no need to reinvent the wheel of plotting.
The experience of the Processing.py mode with Java-libraries-in-Jython seems to have been this: Some Processing(Java) libraries worked without needing changes. Others required minor changes. Others needed a full separate version of the library or would not work at all.
Yep, I will file a issue to describe the integration between processing libraries and Processing.R.
Hi, all.
Now Processing.R has released a new version v1.0.3. In this version most of built-in functions in Processing are supported in Processing.R. And we are building the references documentation for new users: https://processing-r.github.io/Processing.R-docs/.
:)
Hi, all
Processing.R v1.0.4 has been released. There are some new features:
Using grafica in Processing.R
Processing.R is a new mode for PDE, but now the users have to install the mode manually. Then I think maybe it is time to ask how to add Processing.R into PDE contribution manager and what should I do for the integration.
I'd appreciate it if someone could give me some suggestions or requirements @shiffman @jeremydouglass
So excited to see the progress! For getting it into the contribution manager, you should contact @prisonerjohn. It's mostly the same process as with libraries and all the info is here:
https://github.com/processing/processing/wiki/Library-Basics#advertising-your-library
Thanks, I will take a look :-)
Hey, gaocegege, than you for making grafica work in R! I have to give it a try :)
Do you see why the lib could be useful there? I created grafica because processing was missing a simple way to plot data, but R is basically designed for that.
Hi, @jagracar
I am afraid not. The plotting libraries in R could not be used in Processing.R since Processing.R is based on Processing's PApplet.
Ah, ok. So one would use grafica in R when one needs to use a processing lib that is not available in R, use the R statistical libs and plot things at the same time.
Yeah, animation in R is not well supported but it is good in Processing. Statistic computing is not well in Java and Processing but R is one of the best tools. Processing.R wants to combine these two things.
I am not sure whether it is perfect to draw charts in Processing.R. My idea is to do some visual art works with R, for example, fractal.
@jagracar -- re:
That is correct. For example, in Processing.R you could embed a graphica plot in a P3D sketch that uses Processing libraries like peasycam and Processing built-ins like interactive keyboard control -- but is visualizing the contents of matrices / data frames using native R statistical processing.
Another reason to use grafica here is that, while Processing.R combines the strengths of importing Processing libraries and R packages, the support for R packages is extremely limited, and it can only run "pure" R code on its JVM-based R interpreter, renjin. That means
plot()
/ggplot
don't work in Processing.R, because they aren't written in pure native R code. Hence: grafica!Thank you for the explanations!
The mode has been released in PDE: https://forum.processing.org/two/discussion/23848/ann-r-language-mode-for-processing-available-in-pde
Feel free to have a try :)
Hi, Processing.R has a documentation website now: https://processing-r.github.io/
I am migrating the reference and tutorials from Processing.org, the documentation will be ready soon :)
Hi, all.
I released v1.0.6 17 days ago and will present Processing.R in The China-R Conference in Shanghai, China :tada:
Wonderful news, @gaocegege -- and good luck at the conference.
Table and PVector support are really nice additions to what Processing.R can do.
Hi, all
We have some discussions about when to migrate Processing.R to the foundation before. These days I have no enough time to maintain the project and I think it is better to contribute it to the foundation and students from GSoC may have some new ideas about the mode.
WDYT?
We migrated the project to github.com/processing-r/Processing.R. And I have no time to maintain it because of some personal reasons. If anyone is interested in this project, feel free to contribute. And welcome to apply GSoC based on it.