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 http://scn.sap.com/thread/950318 and download the latest NWRFCSDK library.
- Download the RSAP source code from Pier's Github https://github.com/piersharding/RSAP
- 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 Makevars.win (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
** preparing package for lazy loading
*** 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...
- 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:
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' = ';',
'FIELDS' = list(FIELDNAME = list('CARRNAME', 'FORCURAM')),
'QUERY_TABLE' = 'ZSBOOK')
res<-RSAPInvoke(conn, "RFC_READ_TABLE", parms)
flds<-sub("\\s+$", "", res$FIELDS$FIELDNAME)
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