R Snippet output error

I’m having a perplexing error for an R Snippet node. The error I’m getting is:

Execute failed: class org.knime.filehandling.core.data.location.cell.SimpleFSLocationCell cannot be cast to class org.knime.core.data.StringValue (org.knime.filehandling.core.data.location.cell.SimpleFSLocationCell is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @689187df; org.knime.core.data.StringValue is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @615e83ac)

The code is:


data_date ← c(‘2024-01-17’,‘2024-01-24’,‘2024-01-31’,‘2024-02-07’,‘2024-02-14’,‘2024-02-21’,‘2024-02-26’,‘2024-03-06’,‘2024-03-13’,‘2024-03-20’)

lst_folder ← paste0(“C:\Docs\Data Science\Refresh_”,data_date)

fil_locat<- lst_folder[10] #“C:\Docs\Data Science\Refresh_2024-03-06”

files_load ← list.files(path = fil_locat, pattern = “*.csv”, full.names = TRUE)
comb_file ← files_load %>% map_df(~read_csv(.,col_names=TRUE,id=‘path’ )) %>% bind_rows() %>% clean_names() %>% subset(select = -c(path))
knime.out ← comb_file %>% data.table()

I’ve executed line by line with no issues. The default data structure formed was a “tbl_df” for comb_file and I know knime.out requires either a data frame, a table, a list or a matrix.

comb_file is a data table as I verified it with an additional line casting it to data.table() and assigning it back to comb_fil and looking at it within the snippet workspace it looks fine and says it’s a data.table.

Screenshot 2024-04-12 162534

Screenshot 2024-04-12 162645

I’ve tried casting comb_file as a data.frame as well with the same error.

Quite confused if the workspace shows the variable is a data.table and knime.out accepts a data table, why it’s not sending the variable to the output.

@navywings you might want to check what is going on with your list variable if you can convert that to a string.

The code is not really good to read. Maybe you can provide an example that demonstrates the problem in a workflow.

Thanks @mlauber71. The workflow is pretty rudimentary. The List Files/Folders provides a file list of 6 files to the R snippet. The snippet then combines all the files (same structure) into one large file binding the rows.

Screenshot 2024-04-15 122259

I’m trying to compare the combining of files with this code snippet to the knime method of combining csv files using this workflow where rows are appended upon each loop.

They differ and I can’t figure out why. In the R Snippet, it creates a table of 780 rows and 164 columns.

Using the knime loop and appending rows to an output file, I get 780 rows by 85 columns. About half.

While not able to solve this particular issue, I did find a workaround. In the snippet, I wrote the resulting table (comb_file) to a CSV and then just read it with CSV Reader node for use where I needed it. While not as elegant as I had wanted, not a huge issue as long as I’m able to work with the data.

1 Like