Please help with some issue. In my table I have 2 fields: “first_date” and “current_date”. Also I have function “work_days_count” in postgresql database which counts number of business days between two dates.
I try to run in R Snippet next code:
"library(“RPostgreSQL”)
drv <- dbDriver(“PostgreSQL”)
passw <- “pass”
con <- dbConnect(drv, dbname = “dbname”,
host = “111.111.111.1”, port = 5432,
user = “user”, password = passw)
It works without issues when I press button “Eval script” in R Snippet window. But when I try to execute node I get error “Execute failed: Could not parse REXP”.
The usual questions would be which version of R and especially RServe do you use? You will need 1.8.6 and should have a current version of KNIME and R.
In the meantime you could check these discussions if they might help you.
if I may ask why using R Snippet node to connect to PostgreSQL DB and get your workdys? There is PostgreSQL Connector node and after connected you should be able apply same logic to obtain working days. Maybe could be a bit easier
I install R-3.6.2 and Rserve_1.7-3.1. I tried to install 1.8-6 using this install.packages(“Rserve”, “http://rforge.net/”, type = “source”), but it wasn’t installed:
"Warning in untar2(tarfile, files, list, exdir, restore_times) :
failed to copy ‘Rserve/src/client’ to ‘Rserve/clients’
installing source package ‘Rserve’ …
** using staged installation
Warning in system(“sh ./configure.win”) : ‘sh’ not found
ERROR: configuration failed for package ‘Rserve’
removing ‘C:/Program Files/R/R-3.6.2/library/Rserve’
Warning in install.packages :
installation of package ‘Rserve’ had non-zero exit status"
So this error points to a type mismatch. In the R Snippet node, information you plan to pass out of the node needs to be in a dataframe. This would explain why your code works in RStudio but not KNIME.
It makes me wonder if you should try to coerce your table to a dataframe right before the end of your script.
Maybe at the end try
as.data.frame(knime.in)
knime.out <- knime.in
If that doesn’t work, can you identify which line in the script is causing the failure? You can execute line-by-line inside the R Snippet node to find out. I suspect it’s the last line, but it would be good to confirm.
When you drag & drop a new R Snippet node into your workspace are you able to execute it without errors? If that works can you please do the following.
Open Dialog
Reset Workspace
Evaluate lines 1-14
Tell me what the type of knime.in is (shown in the workspace view top right)
Can you see any strange entries in your knime.out data.frame?
I’m very sorry that solving this issues takes so much of your time.
Best
Mark
You do a lot of things in one step. A function that calls a SQL to connect and then appends the result to the knime.in table. Even if that would be a correct syntax it might make sense to split that up and check the intermediate results (also from within the R snippet) if there are some strange results.
Then you could try and switch out the format of the output table (not sure if that would help).
As a workaround, you could try and save the results from the knime.ini file to an ARFF or Parquet file. The result could then be brought back in. as knime.out you could just provide a small data frame or the result of a flow variable or just the initial table.