My good friend and programming guru piers.harding wrote a blog called Analytics with SAP and R where he showed us how to link the wonderful worlds of R and SAP. Yes...SAP...not SAP HANA...but the good old NetWeaver...
Piers build the RSAP extension using Linux...but I'm a Windows user...so we start the discussion and collaboration on how to build the extension for Windows 64 bits.
I gotta say...it wasn't easy...Piers doesn't have a Windows machine...so I needed to test everything...but I don't have previous R extension building experience...so after a lot of hard work from both sides, I'm happy to say that we make it work :wink:
Here are the steps to follow...
With that ready, we can open a CMD session and write the following:
| Header 1 |
|---|
| C:\> R CMD INSTALL --build --preclean --clean --no-multiarch -l C:/RSAP RSAP |
You're going to sure to receive some warnings, but no worries...it should be fine as long as you see these lines...
installing to C:/RSAP/RSAP/libs/x64
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* MD5 sums
packaged installation of 'RSAP' as RSAP_0.03.zip
* DONE (RSAP)
I'm not really sure, if that's enough to have RSAP installed and ready to work...so for the sake of completion you can do this...
Now, we're ready to rock...just like Piers did, I'm going to use a .yml file to host my connection parameters:
| sap.yml |
|---|
ashost: "X.X.X.X" sysnr: "00" client: "520" user: "idadmin" passwd: "XXXXXXXX" lang: EN trace: 1 lcheck: 1 loglevel: warn |
And here's the source code to our example...(For this example you need the libraries: wordcloud and tm).
| Airlines.R |
|---|
library("RSAP") library("tm") library("wordcloud") setwd("C:/Blag/R_Scripts") conn = RSAPConnect("sap.yml") parms <- list('DELIMITER' = ';', 'FIELDS' = list(FIELDNAME = list('CARRNAME', 'FORCURAM')), 'QUERY_TABLE' = 'ZSBOOK') res <- RSAPInvoke(conn, "RFC_READ_TABLE", parms) RSAPClose(conn) sbook<-res$DATA flds<-sub("\\s+$", "", res$FIELDS$FIELDNAME) sbook<-data.frame(colsplit(sbook$WA,";", names=flds)) sbook_agg=aggregate(FORCURAM ~ CARRNAME, data=sbook, FUN=sum) vect<-cbind(sbook_agg$CARRNAME,sbook_agg$FORCURAM) new_vect<-vect[order(vect[,2]),] new_vect<-c(new_vect[,1]) n<-length(new_vect) new_array<-c(n,1) carrname<-levels(sbook_agg$CARRNAME) for(i in 1:n) new_array[i]<-carrname[new_vect[i]] d<-data.frame(word=new_array,freq=new_vect) pdf("Arlines.pdf") wordcloud(d$word,d$freq) dev.off() |
To make the graphic easier to read, I add the PDF option, so a PDF would get generated.

Hope you liked this blog...Piers and I put a big effort and the rewards are awesome...now Linux and Windows users can enjoy RSAP! :lol: