Skip to Content
Author's profile photo Alvaro Tejada Galindo

Running R inside SAP HANA Studio

*DANGER* This is just a silly blog and shouldn’t be taken any seriously.*DANGER*

Ok…you may wonder…why is Blag writing a silly blog? Well…I’m a Developer Evangelist…and it’s my job to keep developers entertained 🙂 Also…I have so free time to spare 😎

As you all may know…SAP HANA Studio runs on top of Eclipse…which means that if we can run R on Eclipse…then we can obviously run R on SAP HANA Studio…that’s exactly what we’re going to do 😉

As easy as it gets…follows this instructions…

  • Go to Help –> Install New Software
  • Put the following repository

EclipseR_001.jpg


  • Choose Walware – StatET

EclipseR_002.jpg


  • Once installed, your SAP HANA Studio will restart and you will need to configure R.
  • Go to Windows –> Preferences.
  • StatET –> Run/Debug –> R Environments –> Add (In my picture, I’m using Edit as I already add it).

EclipseR_003.jpg

EclipseR_004.jpg

  • Either on the Command Line or in RStudio, install the following…
  • install.packages(c(“rj”, “rj.gd”), repos=”http://download.walware.de/rj-1.1“)
  • Also install RJava as well…install.packages(“RJava”)

Now…you need to start the R console…so…

  • Go to the little Green Arrow button and press “R_Console”.

EclipseR_005.jpg

Once that it’s done, we can go ahead and create our R script…

  • Go to File –> New Project –> R Project.
  • On the created R Project, right click and select New –> R Script File.

EclipseR_008.jpg

EclipseR_009.jpg

Copy this code inside your new file…

R_from_SAP_HANA.R

result<-read.table(‘clipboard’,header=TRUE,sep=’;’)

result<-subset(result, !duplicated(DISTANCE))

flights<-data.frame(DISTANCE=as.numeric(result$DISTANCE))

row.names(flights)<-result$FLIGHT

d<-dist(as.matrix(flights))

hc<-hclust(d)

plot(hc)

Now…go to the “Modeler” perspective…open a SQL Console and write the following…

SAP_HANA_Select.sql

SELECT DISTINCT CITYFROM || ‘/’ || CITYTO “FLIGHT”, DISTANCE

FROM SFLIGHT.SPFLI

WHERE DISTANCE > 0

  AND CARRID = ‘SQ’


Run it…and here’s come the funny part…go to the Result tab and select all records…then press Copy Rows, so the selection gets copied into the Clipboard.

EclipseR_010.jpg

Go back to the StatET perspective and click the “Run file in R via command” button…

EclipseR_011.jpg


When you run the code…you’re not going to see any response, unless there’s an error…so just go to the R Graphics tab which is at the bottom where the Console window seats…expand it…and you will see a Cluster Dendogram graphic generated 😉

EclipseR_012.jpg

I told you…this was a very silly post…but at least…we never left the SAP HANA Studio 😛

See you next time!

Blag.

Developer Experience.


Assigned Tags

      13 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Few months back, I was really interested in clusters; I also tried few efforts using few other tools & decided to rest the idea {-; http://goo.gl/PYqN52 Thanks for posting Blag; I will try something out today. Regards, AB

      Author's profile photo Alvaro Tejada Galindo
      Alvaro Tejada Galindo
      Blog Post Author

      Arun:

      Glad to be helpful -:) And don't forget to ping me when you get your idea going -;)

      Greetings,

      Blag.

      Developer Experience.

      Author's profile photo Kumar Mayuresh
      Kumar Mayuresh

      Hi Alvaro

      If your silly blog is so informative then I think there is no need to write anything else 😉 .

      Thanks for a wonderful blog and learning.

      Regards

      Kumar. 🙂  

      Author's profile photo Alvaro Tejada Galindo
      Alvaro Tejada Galindo
      Blog Post Author

      Kumar!

      Maybe it was that silly after all 🙂 Glad you like it 😉

      Greetings,

      Blag.

      Developer Experience.

      Author's profile photo Andy Silvey
      Andy Silvey

      Hi Blag,

      thank you for giving us an update on the SAP world's royal relationship between R and Hana . We've all been following this closely since you announced their first   kiss.

      We all look forward with anticipation to the next update and perhaps even a significant announcement.

      Move over William and Kate 🙂

      All the best,

      Andy.

      Author's profile photo Alvaro Tejada Galindo
      Alvaro Tejada Galindo
      Blog Post Author

      Andy:

      Hehehe...yeah...the first kiss was an important step...but I think there's still more to come and more interesting things to try out 🙂

      Greetings,

      Blag.

      Developer Experience.

      Author's profile photo Denys van Kempen
      Denys van Kempen

      Excellent blog, Blag.

      For all readers, should you wish to know more about R integration with SAP HANA, Philip from the Academy made a whole series about this topic, see http://www.saphana.com/community/implement/hana-academy/#r-integration

      Cheers,

      Denys (SAP HANA Academy)

      Author's profile photo Alvaro Tejada Galindo
      Alvaro Tejada Galindo
      Blog Post Author

      Denys:

      Thanks 🙂 And sure...those SAP HANA Academy videos on R are really good 😎

      I hope that more people start using R and SAP HANA together 😘

      Greetings,

      Blag.

      Developer Experience.

      Author's profile photo Former Member
      Former Member

      Hi Alvaro,

      When I am trying to install using your instructions then my SAP Hana Studio do not restart after installation. Therefore, I do not see it in Preferences window. I have tried manual restart for Hana Studio but no go.

      I can see the EclipseR under "Preferences > Install/Update > Available software sites"

      Am I missing something during installation?

      Regards

      Angad

      Author's profile photo Alvaro Tejada Galindo
      Alvaro Tejada Galindo
      Blog Post Author

      Angad:

      Well...installation should be pretty straightforward...always when you install a new package, Eclipse (SAP HANA Studio) should ask for a restart...did it got installed at all? Try the installation again...

      Greetings,

      Blag.

      Developer Experience.

      Author's profile photo Former Member
      Former Member

      Alvaro,

      That's what I thought too. However, it did not work ever after trying couple of times.

      The only thing that I have not tried is restarting computer (I am running a VM). So I will try that and let you know.

      Regards

      Angad

      Author's profile photo Alvaro Tejada Galindo
      Alvaro Tejada Galindo
      Blog Post Author

      I don't think it's a matter of VM...but please keep me updated...

      Greetings,

      Blag.

      Developer Experience.

      Author's profile photo Former Member
      Former Member

      Hi Alvaro,

      Thank you for the article, it was really helpful.
      I use mac operating system and I am getting following error message :

      "Launching the R Console was cancelled, because it seems starting the R engine failed.

      Please make sure that R package 'rj' (2.0 or compatible) is installed and that the R library paths are set correctly for the R environment configuration 'R'."

      I have 'rj' 2.1 installed on my system,I think the error is due to incorrect mapping in R environment.

      What should be used for R_HOME field ? If I use R.home command on R then it returns

       "/Library/Frameworks/R.framework/Resources".

      Could you please help with the error.

      Thanks again.