Idea: R Language Mode for Processing

Hi, processing :)

R is an open source programming language and software environment for statistical computing and graphics. It ranks 15th in TIOBE Index for February 2017.

Processing.py helps python users to get in touch with visual arts easily and spreads the concept of processing foundation. Processing.R is a good way to expand the user base for processing and reduce learning curve for R users. It is win-win.

I have implemented a prototype: github.com/gaocegege/Processing.R in Sep 2016. It is a demo for R mode, and GSoC is a good chance to make it usable and contribute to processing foundation.

Welcome for any suggestions and opinions and thanks for your browsing :)

image

image

About Me

I’m a freshman in a master’s program in Shanghai Jiao Tong University, my own research orientation is container-based OS virtualization (COS virtualization), so I have contributed to many container-based projects such as docker, kubernetes, runc and so on. I’m a heavy user of GitHub and know the workflow in GitHub.

GitHub: github.com/gaocegege

«1

Comments

  • How is Processing and R related in this concept? Would processing tap on R resources? Or you are defining a new way to access Processing parameters using R notation? In your vision, how would R users benefit when using processing and specifically processing.R? I think it will be great to do vector and matrix operations as processing is always full of for loops. Not sure how easy and feasible this concept is.

    Kf

  • Very interesting and exciting prototype!

    Processing.py is based on Jython -- are you using something similar for R/Java transpiling, or would this take a different approach?

  • re @kfrajer

    Just like processing.py, this prototype uses a JVM-based R interpreter and have some pre-defined functions such as draw(), line(), background() and so on.

    Actually IMO processing.r will take the role of processing.py in python, the users could use standard R data structures including vector and matrix. That is what I want to implement :)

  • re @jeremydouglass

    Yeah, I use renjin.

    Renjin is an interpreter for the R programming language for statistical computing written in Java much like JRuby and Jython are for the Ruby and Python programming languages.

    It is not as mature as jython but has basic functions to interpret R code in JVM. And it is under active dev by https://github.com/psolaimani

  • edited March 2017

    Very cool. I wasn't aware of Renjin. I'm not sure about the digital arts, but R is quite popular in the digital humanities -- I could see R becoming a popular mode.

    I notice that your demo sketch screenshot uses built-in functions like processing$size() processing$background() processing$line() etc. Is this including "processing$" in everything just for the prototype, or is that how you imaging the final Processing.R syntax looking -- or how you think it must be due to some technical limitation? If so, Processing.R may be extremely verbose compared to other modes.

  • Yeah, this is a trick. And I struggle with it for many times.

    The built-in functions in processing have a prefix in R mode because there are some functions already exist in R with the same names as in processing.

    For example R has a function called line, processing also has a function called line.

    I don't have a good idea to solve the problem since they may have same parameter list and name with built-in functions in processing. Then I decided to add a prefix :( It's annoying but unavoidable at that time.

    Is there any suggestions to solve the "same name" problem? Welcome:)

  • Is there any suggestions to solve the "same name" problem?

    PDE's pre-processor! *-:)

  • OMG I have forgotten the power of pre-processing.

    It may be solved gracefully, and I'll try to fix it.

    Big thanks! :)

  • @gaocegege @GoToloop Could you say a bit more about your thought, pre-processing solving the problem?

    Kf

  • @kfrajer, ".pde" files aren't valid ".java" files.
    PDE's pre-processor converts them all as 1 valid ".java" file! \m/

  • Thxs thxs, it makes sense now.

    Kf

  • @kfrajer

    Sorry for the magic comment.

    Just like @GoToLoop said and I can add some details :)

    As for those conflict function names such as line, we could pre-pass all line calls in R mode to processing.line in Java and r$line to standard line function call in R, because I think R mode users call processing built-in functions more often. And if they need to use same name functions in R standard library, r$something works.

    Then processing.r has the same behavior as in Java mode, follow the Law of Least Astonishment to more user-friendly, IMO :)

  • @gaocegege -- I like the idea of using the preprocessor to support syntax like line(x,y,100,100) -- and agree that r$line() would be a good way to give access to the shadowed R built-ins.

  • edited March 2017

    Hi, I have putted Processing.R in Docker and pushed the image to quay.io.

    Now there is just a CLI runner and a VNC server in the image, see the demo in vimeo.

    You can follow the instructions here and play with the prototype in a docker container :)

  • By the way, it is a bad idea to port processing in conatiner based virtualization. But I have no idea how to make users have a try on Processing.R without setting up the environment in their OSes.

  • Hi @gaocegege, this is very exciting to see! One of the limitations of Python Mode is that because it is built on Jython, users cannot access native Python libraries. Would there be similar limitations here or would some of the native features of R be available in an "R mode"?

  • edited March 2017

    Hi @shiffman, I have read your book "Learning Processing" when I started to learn Processing, Nice to get your reply \m/

    As for libraries, I did a feasibility study. Renjin is used in Processing.R as the backend to interpret R code in JVM. Documentation in renjin.org shows differences about packages between GNU R and renjin.

    It supports some of CRAN and BioConductor R libraries and I want to integrate those libraries into Processing.R in GSoC. But I'm not sure whether those packages could be installed in runtime or ahead of time.

    BTW I think Jython supports those libraries which do not require C compilation, although I do not have the experience on it.

  • I think Jython supports those libraries which do not require C compilation

    That is true!

  • Hi, I have shared my draft proposal with The Processing Foundation in GSoC dashboard :)>-

    The proposal includes three main features and some critical bug fixes, welcome to review and comment :)

    I'd appreciate some feedback on the proposal. *-:)

  • If this dashboard is open to the public, you should post a link here as a reference. More people will def check it out.

    Kf

  • Hi, It is visible to Processing admins in GSoC now, I am not sure if it is appropriate to post the link here :-?

  • @gaocegege you are welcome to post a link to your proposal here as well if you would like feedback from the larger community in addition to the review it will receive by Processing in the GSOC system.

  • edited March 2017

    I'd like to share my draft proposal here. Welcome your suggestions :)

  • Question: If you use the pre-processor idea, then people will write code in java but access R environment? For example, would they be able to do matrix operations without the need of explicitly writing for-loops? In processing, the items in the operation will be arrays just to clarify.

    Also in your proposal in the opening, you say: allows users to write real Processing sketches in R. This idea would not reflect the idea of the pre-processor, does it?

    Kf

  • Thanks for your reply :)

    If you use the pre-processor idea, then people will write code in Java but access R environment? For example, would they be able to do matrix operations without the need of explicitly writing for-loops? In processing, the items in the operation will be arrays just to clarify.

    In my opinion, pre-processor is a compiler front end, it just provides some syntactic sugars. It will parse the code and generate valid R code. For example, it will extend the function call line(x, y) to processing$line(x, y).

    People write R code with syntactic sugars provided by pre-processor, then pre-processor expand sugared constructs into more fundamental constructs before processing, and generate valid R code finally.

    TL; DR

    People write R code and they could do matrix operations in R.

    Also in your proposal in the opening, you say: allows users to write real Processing sketches in R. This idea would not reflect the idea of the pre-processor, does it?

    I'm not sure if I understand this point. Actually This sentence is copied from README.md in processing.py Maybe it is not accurate, I want to express that users can write code to use Processing functionalities since it is based a R interpreter in JVM.

    In fact, I'm not good at English 8-| Do you have some suggestions about the expression?

  • @gaocegege

    Sorry for my late response. I am not the right person to ask, mainly bc English is not my first language. However I do recommend on revising the entrance of the proposal to make more clear.

    Sorry to bringing back the idea of the pre-processor in my previous post. I can see it is not that important but more of a side detail.

    Just to have an idea, If I run Processing in R mode, I will be writing an R script in Processing with R notation so I understand? Also, did you get any feedback from your released prototype in Sep 2016? It could be useful to introduce some of that feedback in the proposal if there is anything relevant that will support it. This is just an idea.

    I also want to clarify I am not affiliated to the Foundation but I am just a forum goer. I think this is important for you to know.

    Kf

  • @kfrajer

    :) Thanks for your ideas and suggestions, no need to stand on ceremony.

    I'll review my proposal and make it more clear.

    If I run Processing in R mode, I will be writing an R script in Processing with R notation so I understand?

    Yeah this is what Processing.R want to do.

    Did you get any feedback from your released prototype in Sep 2016?

    I got some feedback here and have added into the proposal such as pre-processor and library support.

    I also want to clarify I am not affiliated to the Foundation but I am just a forum goer. I think this is important for you to know.

    It doesn't matter, your suggestions are helpful to me. You and other members here give me confidence to finish the proposal. :)

  • Hi, I have one another question about mode development, it is a general question.

    I am trying to fix some bugs, and need to put the mode in Processing.app. I did some hacks in processing/processing, replaced the default mode by rewriting app/src/processing/app/Base.java#L404 and #L918. Then I had to recompile the Processing. It works but I'm not sure if there is any easy way to develop and debug a mode for Processing

    I tried to find some docs about mode development for Processing, but got nothing. :-? I'd appreciate it if you could give me some suggestions :)

  • edited April 2017

    And, Could I get the output from the mode?

    Processing app only outputs its own logs when I started it from command line.

    Oh, it is my fault, I have set a system property to control output and forgot to set true.

    ignore this.

  • edited April 2017

    Update: I have fixed some critical bugs, and released a new version:

    Processing.R-v1.0.1 is generally workable. It is packaged with Processing app together and set as the default mode in this distribution. You could download and have a try on it painlessly :)

    Download Link: http://gaocegege.com/Processing.R/

    Again, docker is not a good fit for Processing. >:D< Maybe I will remove docker support in the next version. Or to another extreme, support the whole Processing app with Processing.R in a docker container.

    Welcome to report bugs here! :)

  • I will be great to see an example using matrices or data frames if possible.

    Do you think it is possible to get support for windows in the future?

    Kf

  • R data structures support is a feature to be implemented in GSoC, but now I'm working on usability and bug-fixing.

    As for Windows, it is not supported now because I do not have a Windows environment, so I can not compile the source code for Windows. I will create a Windows virtual machine in the future, and windows will be supported at that time.

    :)

  • edited May 2017

    Thanks for the previous suggestions, Processing.R has been accepted by Processing Foundation as a GSoC project. And my mentor is @jeremydouglass :)

    I'll update the project status here during the GSoC :)

  • Many congratulations, @gacegege, on this exciting project!

  • Are there any active forum members who are R users, or who are familiar with R?

    In particular I'm wondering about forum regulars who I've seen on a lot of threads lately -- for example, @Chrisir @cameyo @colouredmirrorball @GoToLoop @kfrajer @Lord_of_the_Galaxy @neilcsmith_net @TfGuy44 @quark

  • edited May 2017

    @jeremydouglass I tried it once, but I don't use it. I prefer Java, that's why I'm active on this forum in the first place.

  • edited May 2017
  • @jeremydouglass: i worked with R and ggobi some years ago... it's a fantastic language for stat. I'd like to call R library from processing.

  • edited May 2017

    I have yet to try R, but congratulations to @gaocegege for being accepted, and thanks to @jeremydouglass for agreeing to mentor!

    Looking forward to seeing what comes out of this GSoC summer!

  • There is a potential contributor for Processing.R: PatrickMurphy, but I am not sure if he is in Processing Forum. He knows the project from my reddit post.

    Maybe I could get some R users who also use Processing from reddit/r/Rlanguage

  • re @gohai

    Thanks :) Feel free to try Processing.R and welcome your feedback :)

  • @kfrajer: Rust und Julia, no R knowledge til now.

    @gaocegege: Thank you, i will take look!

  • @jeremydouglass

    I have used R but that was seven years ago. I even didn't have a clue you could do object oriented programming with it. I wish the OP the best of luck in his endeavour and maybe statistics can be made fun! (Or even more fun, according to my statistics TA).

  • edited May 2017

    Back when I was writing a lot of R I was not using OOP, but OOP in R looks very interesting.

    The odd thing is that there are (at least) three OO systems for R -- S3, S4, and RC. In S3 classes for R, a class is a vector! S3 and S4 don't match up with Java-style OO very well, though -- if you want methods to belong to classes(!) I believe that RC is the way to go...?

  • @gaocegege --

    Maybe I could get some R users who also use Processing from reddit/r/Rlanguage

    Once there is something to ask them that is a good idea for getting feedback . We may want to request feedback on aspects of the work plan -- and later recruit testers if we can.

  • I have tried tricky OO in R, but it works:

    MyClass <- function(var){
        private.var <- var
        addOne <- function(){
            private.var <<- private.var + 1
        }
        printVar <- function(){
            private.var
        }
        list(printVar = printVar, addOne = addOne)
    }
    

    R's OO support in language level such S3, S4 comes from S Language 3.0 and 4.0. There are many different implementations because of compatibility. It is a little annoying.

  • edited May 2017

    @jeremydouglass

    Yeah, I will get in touch with R community recently. I have some college classmates who contribute to R. It may be helpful to mature the project.

  • edited May 2017

    @gaocegege -- re:

    I have tried tricky OO in R, but it works

    Yes! -- I read your post on "Object Oriented Implementation in R" -- although I could not read it in Chinese, I looked at it in automatic translation. http://gaocegege.com/Blog/r/Roo

    First: developing OO sketches in Processing.R is outside the scope of your GSOC project proposal, and that is fine!

    However, Processing.R is a proposed mode. Someday in the future Processing.R mode users might want to write sketches in R that are structured like intermediate and advanced Processing(Java) sketches.

    In Java mode, these sketches often use standard Java classes. For example:

    The Processing.py mode imitates this in its similar class and object examples:

    By contrast, p5.js provides these examples using JavaScript functions:

    ...or using JavaScript prototypes:

    Even if advanced sketches won't be covered by GSOC, the strategic question I have is:

    1. Given that the planned approach to Processing.R running R on JVM using renjin
    2. ...could this planned approach later extend later to complex Processing examples, either using
      • an R OOP approach (S3, S4, Reference Classes, proto, etc.)
      • or using a functions approach (like p5.js)
      • or something else?
    3. If OOP examples could be supported later, are there any big strategic choices to make now (about the way of using renjin, the syntax of Processing.R, the use of the preprocessor, etc.) that would affect later development?

    In general: are any decisions being made now about how Processing.R works going to make it easier or harder to write advanced Processing.R sketches in the future -- whether they are OO-structured or something else?

  • edited May 2017

    Hi, @jeremydouglass

    Yesterday, I'm trying to do a feasibility analysis on object oriented programming in Processing.R. And S3 is supported in renjin's engine at least. There is a PR which is WIP: Processing.R/pull/40.

    In this PR I implemented the example in Tutorial: Two-dimensional Arrays, and I found that s3 is hard-to-use. In S3, object is a list. And the tutorial needs me to store the object in matrix. It seems that list could not be stored in a matrix directly.

    But, S3 works well in Processing.R since he Cell class is defined with no error in the PR.

Sign In or Register to comment.