Analytics with SAP and R (Windows version)

(This article was first published on Blag's bag of rants, and kindly contributed to R-bloggers)

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

Here are the steps to follow…

  • Install the following packages on RStudio: yaml, reshape and RUnit.
  • Go to this thread and download the latest NWRFCSDK library.
  • Download the RSAP source code from Pier’s Github
  • Download RTools for your R installation version
  • Inside the /src folder copy all the content from the following folders:
    • /include from your R installation
    • /include from your nwrfcsdk folder
    • /lib from your nwrfcsdk folder
  • Change the file (located in RSAP/src) and use this line:
    • PKG_LIBS=sapnwrfc.dll libsapucum.dll

Make sure that you’re using the right R for the NWRFCSDK folder…R 64bit for NWRFCSDK 64bits. You can check this is you go to Environment Variables –> Path and look for something like this C:\Program Files\R\R-2.15.0\bin\x64 (x32 or x64)

With that ready, we can open a CMD session and write the following:

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


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…

  • Go to your RSAP folder…and .zip the RSAP folder that it’s inside.
  • Go to your RStudio and select Tools –> Install Packages –> Choose (.zip) –> Browse your .zip and press Install.

Now, we’re ready to rock…just like Piers did, I’m going to use a .yml file to host my connection parameters:

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).


conn = RSAPConnect("sap.yml")
parms<-list('DELIMITER' = ';',
res<-RSAPInvoke(conn, "RFC_READ_TABLE", parms)

flds<-sub("\\s+$", "", res$FIELDS$FIELDNAME)
sbook<-data.frame(colsplit(sbook$WA,";", names=flds))
sbook_agg=aggregate(FORCURAM ~ CARRNAME, data=sbook, FUN=sum)
for(i in 1:n) new_array[i]<-carrname[new_vect[i]]

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! -:D

To leave a comment for the author, please follow the link and comment on their blog: Blag's bag of rants. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Mango solutions

RStudio homepage

Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training


CRC R books series

Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)