processing-r / Processing.R

R Language Mode in Processing for Creative Coding, created by @gaocegege, maintained by @jeremydouglass
https://processing-r.github.io/
GNU General Public License v3.0
144 stars 16 forks source link

Welcome to have a try on Processing.R #142

Closed gaocegege closed 7 years ago

gaocegege commented 7 years ago

Processing.R has released 5 versions. You can get the latest mode from Release Page.

After you download the mode, place it into Processing "modes" directory:

Now the features in Processing.R include:

Built-in functions in Processing

The documentation website is https://processing-r.github.io/Processing.R-docs/. This documentation is currently incomplete. Most Processing functions are theoretically supported in Processing.R, but many functions have not been tested and some pages have not been edited yet to reflect differences from other Processing modes.

Libraries in Processing: importLibrary()

Processing.R supports importing standard Processing(Java) libraries that enrich the functionality of Processing. The function importLibrary() imports new libraries manually. This has been tested with one library: peasycam, the "dead-simple mouse-driven camera for Processing."

Before trying the example code below, first install the corresponding library peasycam -- for example using the PDE Contribution Manager > Library.

settings <- function() {
    importLibrary("peasycam")
    size(200, 200, P3D)
}

setup <- function() {
    cam = PeasyCam$new(processing, 100)
    cam$setMinimumDistance(50)
    cam$setMaximumDistance(500)
}

draw <- function() {
    rotateX(-.5)
    rotateY(-.5)
    background(0)
    fill(255, 0, 0)
    box(30)
    pushMatrix()
    translate(0, 0, 20)
    fill(0, 0, 255)
    box(5)
    popMatrix()
}

R Packages: library()

Processing.R has limited support for R packages. It will automatically download R packages that are requested using the library() function, so you can use packages directly.

Here is an example using the foreach package:

library(foreach)

foreach(i=1:3) %do%
    print(sqrt(i))

In practice we have only found a few R packages so far that work with Processing.R "out of the box." This is because the package must be pure R and all of its dependencies must also be pure R. There is renjin list of R packages which lists their compatibility with the renjin JVM. Any package fully supported in renjin is theoretically supported in Processing.R.

Limitations in Processing.R

Processing.R is in active development as an experimental pre-release version.

Static sketches: Processing.R does not have a good support for detecting static/active/mix mode. We recommend that all sketches be written in full active mode, defining a separate settings, setup and draw. Even simple sketches should be wrapped in draw(). For example, do not write:

line(0, 10, 90, 100)

That may cause bugs. Instead, write:

draw <- function() {
    line(0, 10, 90, 100)
}

Please try our experimental mode and give us your feedback :) If you want to contribute to this mode, there are issues for new contributors and the architecture documentation.

If you have any problem about the mode, come chat at the Processing.R gitter channel :tada:

skyler-vestal commented 7 years ago

So excited :D!

kfrajer commented 7 years ago

Can P.R run under Windows? If it doesn't, would it be possible in the future?

Kf

gaocegege commented 7 years ago

I haven't test now. I will have a try today or tomorrow :smile:

kfrajer commented 7 years ago

@gaocegege Let me know if you want me to give it a try from my side. I am not sure what file I should get. I have R and P3.3.5 already on my machine and I am looking forward to go through the steps to get the mode running in my Win10 machine.

Kf

gaocegege commented 7 years ago

image

Hi, kf

I have tried to run 2D sketches in Win 10 Virtual Machine. It works. I haven't tried 3D and libraries since my machine could not hold a windows VM for long time.

If you want to have a try, download the releases/download/v1.0.4-alpha/RLangMode.tar.gz from release page and put the mode into c://users/<users>/Documens/Processing/modes.

kfrajer commented 7 years ago

Could I download a branch from git. I don't have access to tar.gz files in Win10.

Kf

gaocegege commented 7 years ago

The code in the repo is just source code, the mode in release page is the output, so downloading the branch doesn't works.

Does zip works for you? I have uploaded a zip file with same content: https://github.com/gaocegege/Processing.R/releases/download/v1.0.4-alpha/RLangMode.zip

kfrajer commented 7 years ago

Thank you. The zip worked. I got the R mode running but I cannot get it to run. I use the example above and I removed all references to peasycam just to keep it simple.

Kf

gaocegege commented 7 years ago

peasycam is in Library's example, you could have a try in Basics's example, for example, https://github.com/gaocegege/Processing.R/blob/master/examples/Basics/BasicOperations/BasicOperations.rpde

kfrajer commented 7 years ago

Hmmm... Nothing happens... no sketch, no error trace... I can try more tomorrow.

Kf

gaocegege commented 7 years ago

:thinking:

Yeah, P.R now doesn't output errors in PDE console, I will have a try when I return home tonight. My machine's memory here is only 4GB :smile:

It is weird but I think it is not a complex bug.

gaocegege commented 7 years ago

I don't meet any problem 🤔 Maybe you could start from a simple sketch: line(0,10,10,0) or something else.

kfrajer commented 7 years ago

@gaocegege Really odd. Nothing even using simple line examples. Let me ask, do I need to setup R in any way?

gaocegege commented 7 years ago

No, R is just a java dependency in the mode, so it is built-in. Could I get your Version of Processing?

kfrajer commented 7 years ago

P3.3.5 64bit

gaocegege commented 7 years ago

It is same as mine. Could you start PDE in console and set an environment variable VERBOSE_RLANG_MODE=true:

VERBOSE_RLANG_MODE=true <PATH_TO_PDE>

It will output the logs of Processing.R in the console.

kfrajer commented 7 years ago

So this is what I did. Starting at the processing.exe location, I issued: set VERBOSE_RLANG_MODE=true and then I started processing from the command prompt. Nothing happened. This is what I issued:

processing-java --sketch=%cd%/sketch_170715a --run

Now from what I know, the sketch name in the previous line corresponds to the name of the folder. The name of the file has an extension rpde so I encountered this next error:

Not a valid sketch folder. C:\Users\C\AppData\Local\Temp\untitled6502517713539763193sketches\sketch_170715a\sketch_170715a.pde does not exist.

I am thinking maybe you want me to do something else? Or am I missing something, as for example, how to handle rpde files via command prompt.

Kf

gaocegege commented 7 years ago

Hi, it is my mistake. I want to get the log of PDE, and I tried to follow the code https://github.com/processing/processing/blob/processing-0262-3.3.5/app/src/processing/app/Base.java#L153 add a debug.txt in APPDATA/roaming/processing, but it doesn't work. Then setting VERBOSE_RLANG_MODE will not work.

processing-java could not run rpde, only PDE's R mode could. I am trying to make Processing in Windows output logs for PDE. It will take me a few days.

My PDE is clean and does not have any other mode or library, maybe you could back up the libraries and modes, then make a clean environment and have another try :thinking:

Sorry for the bad experience with Processing.R in Windows, again :pray: If I know how to output logs for PDE in Windows, I will let you know.

kfrajer commented 7 years ago

So I remove my sketch folder and removed the preferences folder (renamed them) and then I ran processing and allowed it to create the default folders. I closed it and then I moved the R mode right into the modes folder. I created the debug.txt file in the new preference folder and run Processing in R mode and all the same. I am thinking the debugging option needs to be enabled:

https://github.com/processing/processing/blob/processing-0262-3.3.5/app/src/processing/app/Base.java#L64

/**

  • True if heavy debugging error/log messages are enabled. Set to true
  • if an empty file named 'debug' is found in the settings folder.
  • See implementation in createAndShowGUI(). */

On a side note, you said:

My PDE is clean and does not have any other mode or library

Just to clarify, you have the java mode still available there, right?

Kf

gaocegege commented 7 years ago

Yeah, java is built-in and available in my Windows environment

gaocegege commented 7 years ago

image

I have a Windows laptop now and it works well 🤔

jeremydouglass commented 7 years ago

Great! @kfrajer, please try again with the latest release -- or wait a few days and it will be available in PDE > Contributions Manager > Modes.

kfrajer commented 7 years ago

@gaocegege @jeremydouglass I confirmed the R mode works in my machine. See below.

I also ran the provided example RPackageBasics.rpde and it took a while to execute because it was downloading the library. I have R in my computer. Is it possible to tell the R mode to check my current installed libraries under my R stand-alone version? It would be great to have a single pool for the libraries. It is not a deal breaker, and it is really not that important... it is more of a thought.

Now I am interested to see more about how I can integrate R and P3 together. Do you have more examples available? Is there more examples available in the R Mode's reference?

Kf

rmode

gaocegege commented 7 years ago

It is good news. There are lots of examples available in `File -> Examples

2017-08-14 4 2017-08-14 5
jeremydouglass commented 7 years ago

Great news, @kfrajer. If you have ideas and feedback about types of R integration, please share them!

kfrajer commented 7 years ago

Great to see the examples. For some reason I just checked the one that was related to R. I will check them out and see if I can contribute with an example or two.

Cheers,

Kf

gaocegege commented 7 years ago

Hi, Kf

The examples in reference are migrated from Processing reference, so if you'd like to contribute you could see wiki about how to document Processing.R.

Thank you for trying :smiley:

gaocegege commented 7 years ago

The mode has been released in PDE, so I think it is time to close it.

jeremydouglass commented 7 years ago

@gaocegege I was going to remind you to also update the readme... but you already did it!

@kfrajer, definitely let us know by pull request or in the forum if you want to contribute any example sketches.