R evaluation failed "class(knime.out)"

I am brand new to R (long-time user of Knime!) and I have recently picked up a new role where I can combine the two. I have managed to get Knime to find RServe and I found a thread here detailing what I want to do - convert UK Easting/Northing to Long/Lat. I am using the R Snippet node to run the following:

require(“rgdal”) || install.packages(“rgdal”)
require(“sp”) || install.packages(“sp”)

library(rgdal)

prepare UTM coordinates matrix

utmcoor<-SpatialPoints(cbind(knime.in$“Easting”,knime.in$“Northing”), proj4string=CRS(“+proj=utm +zone=30”))
#utmdata$X and utmdata$Y are corresponding to UTM Easting and Northing, respectively.
#zone= UTM zone

converting

longlatcoor<-spTransform(utmcoor,CRS(“+proj=longlat”))

That code was suggested from an old post and found here:

Convert Universal Transverse Mercator (UTM) coordinates to longitude-latitude coordinates in R - Yong Luo (google.com)

However, I keep getting the error Execute failed: R evaluation failed.: “class(knime.out)”…and I don’t really know what that means! Is there something else I need to do? I was just expecting some numbers out.

If it helps, I have a very simple test table of “Easting” and “Northing” (both integers) which I am feeding into the R Snippet.

Hi @JWebb
Both in R and Py Snippet, it’s mandatory to send a data frame object to the output port.

Said so, ‘utmcoor’ and ‘longlatcoor’ (returned from ‘spatial points’ [sp] and ‘rgdal’ libraries) are list objects. Then you will need to subset a data frame from this ‘longlatcoor’ list and send it to the output port.

Let me know if further help is needed.

BR

1 Like

I need to do some R training because I haven’t got a clue what that means :sweat_smile: I was just copying the example, to be honest! Thanks; I’ll try and figure something out. At least it’s not a setting issue.

@JWebb often a command like

knime.out <- as.data.frame(<your content>)

goes a long way. You will have to deal with the structure of the data (often strings) later but it will work. If you just want to store something from within R and use it later again in R you could also save something as .rdata:

2 Likes

Perfect! That worked well. A simple solution which works for me for the time being. Once I get my head round R a bit more, I’m sure things will become clearer, but I am happy that works for now :slight_smile: Thank you!

It’s not giving the correct answer, but at least I am getting something out!

2 Likes

Well done @JWebb ! The first step is to understand the few KNIME-R connection rules. Combine KNIME and R (Py) becomes a perfect tool for non native programmers as myself.

If you want us to review the workflow, or code, or test the input data, don’t hesitate to share.

BR

1 Like

That is so true :slight_smile: - these things:

1 Like

I think it’s a good start that I have made the connection and managed to get it to so something in my first week using it!

I am trying to convert UK Easting/Northing coordinates to lat/long. I have taken 537869, 178976 (somewhere in Greenwich) as an example, but the lat/long converted point appears to be in the Atlantic Ocean somewhere off the coast off the Ivory Coast! I appreciate, however, this is not an R forum, so I can try and raise the question elsewhere. I also appreciate, however, that you may be intrigued, so this is what I am using:

require(“rgdal”) || install.packages(“rgdal”)
require(“sp”) || install.packages(“sp”)

library(rgdal)

prepare UTM coordinates matrix

utmcoor<-SpatialPoints(cbind(knime.in$“Easting”,knime.in$“Northing”), proj4string=CRS(“+proj=utm +zone=30”))
#utmdata$X and utmdata$Y are corresponding to UTM Easting and Northing, respectively.
#zone= UTM zone

converting

longlatcoor<-spTransform(utmcoor,CRS(“+proj=longlat”))

knime.out ← data.frame(longlatcoor)

I don’t think UTM is the correct system. I just need to find someone who has managed it for BNG and steal their code :slight_smile: Which is harder to find than it sounds!

@JWebb could you provide us with some sample data? With geo data the underlying system is always a thing (there are lots of them).

Then you might want to check out the planned KNIME extension about Geo data

There will be a presentation you also can attend online at the KNIME Fall Summit 2022

1 Like

The example I tried was:

East./North. 537869 , 178976. Was expecting 51.492927 , -0.015449524, but got the result -2.6595478348955846, 1.6192189249637292 instead.

That’s interesting. I might see if my organisation’s “Mr. Maps” is interested!

@JWebb , it’s not additional work as I already tested it to check object type…

You aren’t applying the correct CRS conversion… test this one:

library(sp)
library(tidyverse)
library(rgdal)

test.Easting <- c(537869)
test.Northing <- c(178976)
lat.long.df <- data.frame(test.Easting, test.Northing)

coordinates(lat.long.df) <- ~test.Northing + test.Easting
str(lat.long.df)

# EPSG code of United Kingdom is 27700,  "https://epsg.io/27700"
# get it using CRS function
proj4string(lat.long.df) <- CRS("+init=epsg:27700")

# convert this to Longitude-Latitude data
# WGS84 "https://epsg.io/4326"
dist.location <- spTransform(lat.long.df, CRS("+init=epsg:4326"))
str(dist.location)

x <- dist.location@coords[1]
y <- dist.location@coords[2]
output <- data.frame(x, y)
knime.out <- output

BR

1 Like

That one has not worked, I’m afraid. I have plotted both “Greenwich” points x/y and y/x just to make sure I wasn’t getting them the wrong way round. One was in the sea off the Seychelles and one was in the sea off the coast of Northern Ireland! The result it gave me was -5.430676428765502 for x and 54.68721915653498 for y. I’m sure it’s just a case of figuring out which conversion scheme to use, so thank you for your input and I shall have to investigate the correct numbers.

Update:
I completely overlooked something! I can specify the coordinate system I am using in the program, so I do not actually need to convert it. however, I didn’t realise I was able to do that until reading your feedback to my last post, so you did solve my problem in a roundabout way! Thank you for the input.

2 Likes

@JWebb glad you found it. Maybe you can provide your solution with the example and a description what you did in a short workflow. That might help others in the future :slight_smile:

It was not in Knime, I’m afraid. No lick with getting that R Snippet to convert the coordinates effectively, I’m afraid.

The ultimate goal was to feed into Tableau to aid some work I am doing and Tableau allows you to specify the coordinate system you are using with its MAKEPOINT function. I didn’t realise that was such a thing until I saw @gonhaddock use the number codes from epsg.io

At least this gives me a workaround until I can get better with R and maybe have a reasonable idea of what is going on!

The code is right but with a bug in row 9…

I thought lat.-long. order had a sorting meaning… but it doesn’t

The correct form is:

coordinates(lat.long.df) <- ~test.Easting + test.Northing

This currently fixes it, and works in RStudio, returning the mentioned result:

image

but returning an error in KNIME (RStudio oversees it):

"To mute warnings of possible GDAL/OSR exportToProj4() degradation,
use options(“rgdal_show_exportToProj4_warnings”=“none”) before loading sp or rgdal.
Error: subscript out of bounds …"

There are some literature about this Error related to Windows, but I don’t have time now for debugging.

Just for the records.

1 Like

@JWebb
Your coding resulted to be more optimal than the testing mine. Usually I need a workaround to fully understand ‘R to facts’ conceptual relation.

This is the code working within KNIME as stated in your posted link :

And the KNIME workflow:


20221107_R_Coordinate_Reference_Systems_v0.knwf (14.2 KB)

BR

4 Likes

Sorry, I overlooked this reponse in my notifications. These results look like the ones I am after :slight_smile: Thank you for your input

1 Like