cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Have your say in shaping JMP's future by participating in the new JMP Wish List Prioritization Survey
Choose Language Hide Translation Bar
paul_vanoppen
Level II

R integration, issue with R Submit File

Hi,

 

Update: I found a workaround which I posted in the comments.

This JSL script runs without any problems (I am using JMP 16.0.0 (512257) under Windows 10 Pro 64 bit) and generates the expected png output from ggplot in JMP:

LoadExprs = Expr(
	InitR = Expr(
		R Init();
		
		R Submit( "
			library(dplyr)
			library(ggplot2)
			library(palmerpenguins)
		" );
	);
	
	MakePlot = Expr(
		R Submit(
			Eval Insert(
				"\[
				ggplot(data = penguins, aes(x = bill_length_mm, y = flipper_length_mm, colour = species)) +
				geom_point() +
				facet_wrap(. ~ island, nrow = 3)
			]\
			"
			);
		);
		
	);
	
	CapturePlot = Expr(
		JMP_plot = R Get Graphics( png );
		New Window( "Imported Plot", Picture Box( JMP_Plot ) );
	);
	
	RunClose = Expr(
		R Term(); //Close r connection
	);
);
LoadExprs;
InitR;
MakePlot;
CapturePlot;
RunClose;

If I try to call the R script directly, with the exact same R code, it fails with the error message "Get data for ''png" failed".

Here's the JSL script:

LoadExprs = Expr(
	InitR = Expr(
		R Init();
	);

	RunR = Expr(
		R Submit File( "C:\Users\xxx\R_projects\JMP\R_JPM_integration_1.R" );
	);
	
	CapturePlot = Expr(
		JMP_plot = R Get Graphics( png );
		New Window( "Imported Plot", Picture Box( JMP_Plot ) );
	);
		
	RunClose = Expr(
		R Term(); //Close r connection
	);
);
LoadExprs;
InitR;
RunR;
CapturePlot;
RunClose;

This simplified JSL script, my first attempt, also fails with the same error code:

R Init();
R Submit File( "C:\Users\xxx\R_projects\JMP\R_JPM_integration_1.R" );
R Get Graphics( png );
R Term();

And here's the simple R-script I use for this test:

library(dplyr)
library(ggplot2)
library(palmerpenguins)

ggplot(data = penguins, aes(x = bill_length_mm, y = flipper_length_mm, colour = species)) +
  geom_point() +
  facet_wrap(. ~ island, nrow = 3)

Which is identical to the R code in the first script.

Is there a problem with the R Submit File call? What am I missing?

I would prefer to use R Submit File as it saves typing work.

1 ACCEPTED SOLUTION

Accepted Solutions
paul_vanoppen
Level II

Re: R integration, issue with R Submit File

And I do not need the windows() function call either. Just explicitly plotting by calling the plot function is sufficient!

I did find that the JMP error message ("Get data for "png" failed") disappears once I use the windows function call in R. I just end up with an empty window as nothing is explicitly plotted to it.

The code below works fine in conjunction with the JSL scipt using R submit File.

library(dplyr)
library(ggplot2)
library(palmerpenguins)

p <- ggplot(data = penguins, aes(x = bill_length_mm, y = flipper_length_mm, colour = species)) +
  geom_point() +
  facet_wrap(. ~ island, nrow = 3)
plot(p)

 

 

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: R integration, issue with R Submit File

I ran your code under 16.2 and 17.0 running on Windows 10 64bit and got the "Get data for ''png" failed". when running under JMP.

Jim
ih
Super User (Alumni) ih
Super User (Alumni)

Re: R integration, issue with R Submit File

I think when using R Submit File the plot is not written to the console (I could be wrong, I haven't dug in enough to be sure).   I have gotten around this by reading the R file as text into JMP and then submitting it using R Submit.

paul_vanoppen
Level II

Re: R integration, issue with R Submit File

Thanks!

Indeed, R Submit works just fine, see code below.

Still, I would like to determine how to make R Submit File work as it prevents having to copy (possibly large) R scripts.

Your assessment of why R Submit File does not work sounds plausible but would require an SAS/JMP expert to confirm.

LoadExprs = Expr(
	InitR = Expr(
		R Init();
	);

	RunR = Expr(
		R Submit ( "
		   library(dplyr)
		   library(ggplot2)
		   library(palmerpenguins)

		   ggplot(data = penguins, aes(x = bill_length_mm, y = flipper_length_mm, colour = species)) +
			  geom_point() +
			  facet_wrap(. ~ island, nrow = 3)
		" );
	);
	
	CapturePlot = Expr(
		JMP_plot = R Get Graphics( png );
		New Window( "Imported Plot", Picture Box( JMP_Plot ) );
	);
		
	RunClose = Expr(
		R Term(); //Close r connection
	);
);
LoadExprs;
InitR;
RunR;
CapturePlot;
RunClose;

 

paul_vanoppen
Level II

Re: R integration, issue with R Submit File

I found a workaround by forcing R to open a graphics window and explicitly plot the graph to that window:

 

library(dplyr)
library(ggplot2)
library(palmerpenguins)

windows(800,600)
p <- ggplot(data = penguins, aes(x = bill_length_mm, y = flipper_length_mm, colour = species)) +
  geom_point() +
  facet_wrap(. ~ island, nrow = 3)
plot(p)

I now need to worry about plot size but that's acceptable. Here's a screenshot of the script with the JMP graphics window:

paul_vanoppen_1-1673398567643.png

 

 

paul_vanoppen
Level II

Re: R integration, issue with R Submit File

And I do not need the windows() function call either. Just explicitly plotting by calling the plot function is sufficient!

I did find that the JMP error message ("Get data for "png" failed") disappears once I use the windows function call in R. I just end up with an empty window as nothing is explicitly plotted to it.

The code below works fine in conjunction with the JSL scipt using R submit File.

library(dplyr)
library(ggplot2)
library(palmerpenguins)

p <- ggplot(data = penguins, aes(x = bill_length_mm, y = flipper_length_mm, colour = species)) +
  geom_point() +
  facet_wrap(. ~ island, nrow = 3)
plot(p)