handling empty R dataframes using R to Table node

I have R code transforming a table based on some conditions. Depending on the conditions the table may be empty. How do I handle an empty table using the R to Table node?

If the dataframe is empty, I set the value to 0. I simply pass the dataframe to the knime out variable like so:
knime.out <- df1

However in the R to Table node i get the following error:

ERROR R to Table 0:34 Execute failed: CODING PROBLEM importBufferedDataTable(): Supporting only ‘data.frame’, ‘data.table’, ‘matrix’ and ‘list’ for type of “knime.out” (was ‘numeric’).

I want to be able to pass the table if it exists and pass the numeric 0 if it doesnt. I used the following code:

if (is.numeric(df1) == TRUE){
	knime.out <- 0
} else{
knime.out <- df1 # insert your data.frame here
}

Problem is that the R to Table node seems to only accepts table formats.

Any advice on how to handle this?
Thank You

@thentangler if df is a numeric variable you will have to convert it into a data frame

knime.out <- as.data.frame(df)

5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.