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:
drv <- dbDriver(“PostgreSQL”)
passw <- “pass”
con <- dbConnect(drv, dbname = “dbname”,
host = “188.8.131.52”, port = 5432,
user = “user”, password = passw)
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
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
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.
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.