R in KNIME

Hi I am looking to implement an R code in KNIME. The R Snippet seems to be very different as compared to the bash script. It keeps giving me an error like "Execute failed: (NegativeArraySizeException)"

If there is indeed an R tutorial for KNIME please let me know thank you

 

Varun

Can you please post the R script, you are trying to execute. Cheers.


z <- read.table(textConnection(" X Y1
1200 1.375
4000 0.464
1333.33 0.148
444.44 0.047
148.148 0.014
49.383 0.005
16.461 0.004"),
header=TRUE)                

with(z,plot(X,Y1))
with(z[-1,],plot(X,Y1))
tmpf <- function(X,a,b,cc,d) d + ((a-d)/(1+(X/cc)^b))
curve(tmpf(x,0.5,-1,1000,0),add=TRUE)

## fix a and d to reasonable values, fit b and cc
n1 <- nls(Y1~tmpf(X,a=0.7,b,cc,d=0),
    data=z[-1,],
    start=list(cc=1000,b=-1))

with(as.list(coef(n1)),curve(tmpf(x,a=0.7,b,cc=1000,d=0),add=TRUE,col=2))

## now use b and cc as starting values, fit a and d
n2 <- nls(Y1~tmpf(X,a,b=-1.721,cc=2738,d),
    data=z[-1,],
    start=list(a=0.7,d=0))

with(as.list(c(coef(n1),coef(n2))),curve(tmpf(x,a,b,cc,d),add=TRUE,col=4))

## now fit all simultaneously
n3 <- nls(Y1~tmpf(X,a,b,cc,d),
    data=z[-1,],
    start=as.list(c(coef(n1),coef(n2))))
coef(n3)
with(as.list(coef(n3)),curve(tmpf(x,a,b,cc,d),add=TRUE,col=5))

The above is the R script I wanted to implement....Please let me know

Varun

Your R script runs through the R Snippet as it is. I only added a line "R <- R" at the end that forwards the input data to the out-port. If you want to use the data that comes into this node, you need to refer to the variable R, the result of the script must be again in the variable R. Hope this helps?

Thank you Gabriel that did help. I did output the output to the R variable. It however brings me to another problem point, rather two.

Before that let me tell you about my R code, it calculates the solution for the 4 parameters a,b,cc,d; given the above (X,Y) data. I am then given new Y data and calculate respective values of X.

1. I used the R learner node which makes a model from my R program. I then link it to the R predictor node, input the model and the new data (which is just a column of the new Y values). It gives me an error saying

R error output:

> setwd("/tmp");
> R <- read.csv("/tmp/R-inDataTempFile-2699785880052181470.csv", header = TRUE, row.names = 1);
> RDATA<-R;
> load("/tmp/~knime5268831457162570072.R");
> RMODEL<-R;
> R<-cbind(RDATA, predict(RMODEL, RDATA));
Error in UseMethod("predict") :
  no applicable method for 'predict' applied to an object of class "c('double', 'numeric')"
Calls: cbind -> predict
Execution halted

2. In the above program, I have a curve function which keeps plotting and adding curves till the end using the curve() and with() functions. Is there a possibility to do this using Rview?

I have knime2.4.2

Thank you

Varun

Rectified error 1, however the problem with the graphs still remain

Sorry for the delay. Did you have a look into the R View (Local) node already that allows executing R scripts that generate R plots. Please let me know which problem you encounter.

how I can used multiples functions in R snippet for variables for examples sum, count in a same node 

R<-sum(R[4])

R<-nrow(R[1])

I am doing in different nodes but I want to same node. please help me!

because I do not know howfrownfrown