using baseballr in Knime


Need help using baseballr in Knime. I want to bring in pitcher and batter data in 2023 to calculate their fantasy totals but am getting the generic error message

ERROR R Source (Table) 0:13 Execute failed: R evaluation failed.: “knime.tmp.ret<-NULL;printError<-function(e) message(paste(‘Error:’,conditionMessage(e)));for(exp in tryCatch(parse(text=knime.tmp.script),error=printError)){tryCatch(knime.tmp.ret<-withVisible(eval(exp)),error=printError)
if(!is.null(knime.tmp.ret)) {if(knime.tmp.ret$visible) tryCatch(print(knime.tmp.ret$value),error=printError)}};rm(knime.tmp.script,exp,printError);knime.tmp.ret$value”

@mbarzyk welcome to the KNIME forum. You will have to extract the data a a data frame.

Something like this

library(baseballr)

# Example: Fetching player statistics for a specific player
# Use playerid_lookup to get player's ID based on name
player_stats <- playerid_lookup("Trout", "Mike")

# Ensure the output is explicitly a data frame
player_stats_df <- as.data.frame(player_stats)

# Output the data frame
knime.out <- player_stats_df
2 Likes

Can you elaborate? I think your response had a typo in it.

I pasted your code into the R Source Node and evaluated the script - it returned the following.

@mbarzyk the code is perfectly fine and in RStudio it gives the result.

Unfortunately every now and then it seems a KNIME version is screwing up the data transfer between KNIME and R. And then it takes time and convincing to sort this out.

https://forum.knime.com/search?q=%22knime.tmp.ret%22%20order%3Alatest

1 Like

@mbarzyk with the community nodes this seems to work. Maybe not the most elegant solution.

Does KNIME Interactive R Statistics Integration v4.2.3 work with KNIME Analytics Platform v4.2.0? Could that be the issue? I’ve installed the R Statistics Integration v4.2.3 following each step in the installation guide and have been getting the aforementioned errors.

@k10shetty1 maybe you can take a look at this example and see why the KNIME R node might fail under MacOS while the community node does succed.

@mbarzyk and indeed there was a problem with R, knime and versions before 4.5. so maybe an update to 4.7 might help

@bwilhelm maybe you can weight in if this is a known error that seems to resurface with KNIME 5.2.x.

Hi all,
The linked post is not related. It was only an issue with KNIME AP 4.5.0 and 4.5.1. Not with previous versions, and it has not resurfaced with 5.2.x. However, updating is a good idea. KNIME AP 4.2.0 is quite outdated and a few bug fixes have been implemented since then.

@bwilhelm we currently see problems with the KNIME and R nodes again. Maybe you can have a look at the example and see if this does work on a Mac:

image

Hi @mlauber71,

I tried running the workflow you shared on macOS and yes, the R Snippet node (KNIME Interactive R Statistics) fails with this error message:

Execute failed: R evaluation failed.: "knime.tmp.ret<-NULL;printError<-function(e) message(paste('Error:',conditionMessage(e)));for(exp in tryCatch(parse(text=knime.tmp.script),error=printError)){tryCatch(knime.tmp.ret<-withVisible(eval(exp)),error=printError) if(!is.null(knime.tmp.ret)) {if(knime.tmp.ret$visible) tryCatch(print(knime.tmp.ret$value),error=printError)}};rm(knime.tmp.script,exp,printError);knime.tmp.ret$value"

But, it executes successfully on Windows and Linux. So, I tried an earlier version of KNIME on macOS (4.7.7) and it fails there too. I’m not R expert (I’m sure you are), but is it possible that this is an issue with the used library on macOS in general? Asking since I’ve heard that some R libraries are not working as expected on macOS.

@armingrudd there are pretty standard R libraries that do not seem to work properly. And they have done so in the past (my impression). It seems that the output is not properly captured. The community node does not have the same problems.

In this example a simple plot does work, others do not. GGplot2 is a pretty common library.

1 Like

Thank you @mlauber71 for the examples. I can reproduce the same issue in the previous example here as well (only macOS).
So, this has been the same before? Becasue I can reproduce on 4.7.7 and 5.2.2.
Do you know any earlier version that this was working fine (on macOS)?
I will discuss this internally as well.

@armingrudd to be honst I cannot exactly recall when the problems started. There was this debate around KNIME 4.5 - where there were some changes and some cases worked.

I have rewritten a workflow to use the R community nodes since I was experiencing problems with the R nodes (on Mac). But it was difficult to pin them down.

I have started an article about visualizations and R with KNIME but stopped because I lacked the energy to go thru convincing someone that there is a problem :slight_smile: - so if you might want to take an additional look that would be great. Not doing much with R at the moment.

1 Like

@armingrudd, @bwilhelm there was a small update for the R Scripting extension and now everything seems to work on KNIME 5.2.2 :slight_smile: - not sure if it was you, but thank you anyway.

1 Like

@mlauber71 this update only updated some metadata of the extension, there haven’t been functional changes in a long time… Great that it is working for you right now, but @armingrudd and I can still reproduce the error with 5.2.2, so there must still be something off.

While this spurious problem is “luckily” reproducible on my machine, I’ll try to understand what’s going wrong.

3 Likes

Phew. That’s a weird one. It seems to be the same issue as here: Table to R not able to load library. Our R Snippet node apparently cannot connect to the internet to download data.

If I run the script from the node in a standalone R it works without problems, and also in the community (MPI) R snippet node.

If I run the command player_stats <- playerid_lookup("Trout", "Mike") in a standalone R session, save the result to a table, and replace the line in the R Snippet node by player_stats <- read.table(...) then everything works as expected.

I assume the reason is that we’re running the R code from KNIME via RServe and communicate via sockets. Maybe, for some reason, this is configured in a way that it cannot talk to the “outside world”. I had a glance at the code but did not find a place where this might be configured that way…

Does this help a bit?

2 Likes