Skip to Content

Analytics with SAP and R (Windows version)

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:

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


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’ = ‘;’,

              ‘FIELDS’ = list(FIELDNAME = list(‘CARRNAME’, ‘FORCURAM’)),

              ‘QUERY_TABLE’ = ‘ZSBOOK’)

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! 😆

You must be Logged on to comment or reply to a post.
  • Brilliant!  Thanks for all the help with the build.  Next step will be to package it up with RStudio, so Windows users can enjoy it without having to do the build.


    Piers Harding.

    • Thanks Piers -:) Always a pleasure to work with you...I'm sure a lot of people are going to enjoy the Windows package -;) We should promote more the use of R in the enterprise...



  • Good morning Gurus:-)

    although i am a littlebit late because your development is already three years old, i am really interested in this topic and have an actual research question which i try to solve with your workaround.

    I´ve tried to follow Mr. Galindo´s installation steps but i don´t get the thing up and running.

    In my desperation i wrote Mr. Galindo an email where i´ve documented all the steps and my error messages. I have a lot of experience with R and with SAP  in particular with SAP BW/BI but i´ve never developed packages in the way you did it. So i think i have a general understanding problem.

    Because i was not able to attach a .docx or .pdf file (because of the screenshots) to this forum i wrote the email to Mr. Galindo.

    I would really appreciate your help!

    Thank you in advance!

    Kind regards


    • Hi -

      I have not looked at this for a while, but the main problem is that something core changed with R between version 2 and 3, which broke the windows build.  I do not have access to the RFC SDK, or a Windows development environment  so I have not ever been able to solve this.  My advice is to stick with Linux as the build is much simpler and the options for dealing with build problems are much better/easier.  Have you considered running Linux in virtual box or something like boot2docker?


      Piers Harding.

      • It's been a while indeed 🙂 But...I have some wonderful news...I was finally able to make it work on R 3.2.0! 😀

        Marcel Katzmann You have a couple of mistakes on the PDF you send here it goes 😉

        • The contents of RSAP/src must have what comes from Piers's source and you need to add the contents of "/include from your R installation" "/include from your nwrfcsdk folder" and "/lib from your nwrfcsdk folder straight into the basically you need to end up with R_ext and the rest should be all the files from the mentioned folders...
        • Regarding the "C:\Program Files\R\R-2.15.0\bin\x64...that needs to be on the Path variable...on the R variable...just to make sure, add this to the Path variable on both System and User Environment Variables...
        • R Tools must much your installation version...I can see that yours match...mine didn't...that's why it wasn't soon as I magically start compiling...

        I just tested and it worked perfectly 🙂 and's been a while since I used R on Ubuntu VM is where I spend all my development time 😉

        If you want I can send you the or you can try to compile it again...I will be more happy to help you out 🙂



        Development Culture.

  • Good evening Blag and Piers,

    thank you both so much for the quick answers. With your help i am a big step further in compiling the RSAP package, but i am still struggling with it:-(

    The content of my is now:

    PKG_LIBS=sapnwrfc.dll libsapucum.dll


    When I open the CMD-Session i now get the error message:


    This means:

    Warning: not valid package 'RSAP'

    Error: Error: no packages stated.

    I tried to do exactly what you mentioned me to do and I checked the Path variables for system and user also:


    Now i dont know what to do...

    From Piers source i put everything in my C:/RSAP/src folder:

    1. the RSAP.c file

    2. the above shown file

    3. the file

    4. the (empty) file

    My C:/RSAP/src folder contains the following files:


    Do you have an idea what is still wrong?

    Thank you so much in advance!

    Yours Marcel

    • The only thing that comes to my mind right now is to execute the command outside the RSAP folder...

      C:\>R CMD INSTALL --build --preclean --clean --no-multiarch -l C:/RSAP RSAP

      Also...I don't think it really matter...but here's my RSAP Folder /src...




      Development Culture.

  • Hey Blag, thanks again for your quick answer! 🙂

    I already tried the compilation out of the C:/  directory but the error message is exactly the same like the one shown above that means it behaves as you supposed:-(

    What I did furthermore was the comparison of your source folder and mine. There are the following differences:

    1. You have a file RSAP.dll (where did you get it from???)

    2. You have the subfolder R_ext (I copied the content directly into C:/RSAP as you mentioned me to do)

    3. There are some tiny deviations regarding the respective size in kb of some of files, but i think this cannot be the problem, but its due to the newer nwrfcsdk version i use, because i have downloaded it 2-weeks ago.

    And one other question is still left: what do you mean by:

    '...that needs to be on the Path variable...on the R variable'

    as i have shown above i set the system variable 'Path' and and the user variable 'Path' to

    'C:\Program Files\R\R-2.15.0\bin\x64'

    What is meant by 'on the R variable'?

    Is the correct as shown above?

    Please excuse my 'silly' questions but i have a feeling i am very close to the solution;-)



    • Marcel:

      RSAP.dll is the file generated by the compilation of the RSAP package 🙂

      Yep...I don't think the filesize has anything to do with version of nwrfcsdk is quite old 🙁 But that shouldn't matter...

      I meant..."not on the R variable" but on the Path variable...I saw in your screens that you we're using an R variable instead of the Path variable...that's all 🙂

      My looks like this...


      PKG_LIBS=sapnwrfc.dll libsapucum.dll

      And questions are you know how many emails I exchanged with Piers to make this work? Over 60 🙂 So...feel free to keep asking until you manage to compile the package...I have learned that doing anything on Windows is way harder that doing it on Linux...that's why I spend 90% of my time on my Ubuntu VM 😉



      Development Culture.

  • Hello again;-)

    Thank you for your patience!

    Ok, even your didn´t help:-(

    You use the path C:/nwrfcsdk/include in your although you have copied the content of the include into C:/RSAP/src this confuses me a littlebit;-) But as I said it doesnt help...

    Yes I know that the whole thing is much easier with Linux!!! Piers recommended it also in our E-Mail conversation.

    The thing is i want to access a BW system in the company where i work and all the clients have windows laptops...

    For a fast prototyp i could use the linux workaround and acces a system from university but this makes it hard for me to transfer it to the business and research combination thing...

    I will not give up and i will inform you when it finally works!

    Thank you for all your help!


    • You use the path C:/nwrfcsdk/include in your although you have copied the content of the include into C:/RSAP/src this confuses me a littlebit;-) But as I said it doesnt help...

      That's true 🙂 Just realized that LOL Anyway...I change it to this...


      And it works't really matter where it is 😉

      Now...I find weird that it gives you the message...

      Warning: not valid package 'RSAP'

      Error: Error: no packages stated.

      As it should at least try to compile it...but doesn't look like it's not even trying 🙁

      Can you execute "gdb" on your command line? Does it enter the compiler? Maybe the path for RTools is not configure properly...that would be weird...but doesn't hurt to check...



      Development Culture.

  • When i was installing Rtools i was wondering in one step;-)

    So i deinstalled it and used the following options:






    The thing which happens now is, that Rtools changes my Path variable from C:\Program Files\R\R-2.15.0\bin\x64 to c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin;C:\Program Files\R\R-2.15.0\bin\x64


  • /
    • That's good to know 🙂 Have you tried to compile the RSAP library again? I'm sure it should work assumption is that wasn't grabbing the compilers from RTools...



      Development Culture.

  • yes i am still trying... I did a reboot too,because we are in the windows world;-)

    but it is still the same error message?!?!

    Is it necessary that R is running or RStudio is running? And if yes, which packages should be used via "library(XXX)"?

  • And another thing: Rtools is now installed to the directory C:/R64.

    My R-Installation itself is in C:\Program Files\R\R-2.15.0 and the C:/RSAP/src directory contains all the "known" files...

    what did you mean by 'excecute gdb'?

    Open a CMD Session and try to type this three letters?!

    • That's weird 🙁 And nope...R or RStudio doesn't need to be running...I assumed that it was a RTools it confuses even more that it's not even trying to compile...

      What happens if you simply do this...


      And yep...that's what I'm a command line and type




      Development Culture.

  • Its all the same stupid error message:-(


    As you said it didn´t even try to compile... gdb doesn´t work also...

    Is it necessary to copy any parts of the Rtools installation to the RSAP Folder? And in my R Installation there is also a under: C:\Program Files\R\R-2.15.0\src\library\windlgs\src with the content 'PKG_LIBS=$(GRAPHAPP_LIB)'...

    Ok i identified another problem... Can you please tell me where your R Win library Folder is located?  I dont know why but i have a folder: C:\Users\Marcel\Documents\R\win-library\2.15 in which my "new" packages are loacated:


    Although i have in addition to this i have the C:\Program Files\R\R-2.15.0\library with older packages, but without the above shown new once...

    I copied them to C:\Program Files\R\R-2.15.0\library but it doesnt work...

    • I expected that "gdb" was not going to work...when you said...And another thing: Rtools is now installed to the directory C:/R64.

      Not sure why that happend as I have mine installed on C:/RTools...but should modify the PATH variable to be like this...

      c:\R64\Rtools\bin;c:R64\Rtools\gcc-4.6.3\bin;C:\Program Files\R\R-2.15.0\bin\x64

      Or just c:\R64\bin;c:R64\gcc-4.6.3\bin;C:\Program Files\R\R-2.15.0\bin\x64

      Depending on your exact folder configuration..."gdb" must be callable from the command line...

      My R libraries are installed on C:/Users/I830502/AppData/Local/R

      But I don't think that matters...while R can read doesn't really matter where they are 🙂



      Development Culture.

  • Hello and good evening Blag 😉

    it was really late yesterday and a long day in the office today but now it´s RSAP time again 🙂

    First of all, thank you for all your hints and tips yesterday!!!!

    I dont know why i have a R64 Folder, it has nothing to do with Rtools and the good news is that Rtools is installed in C:/Rtools as it should be.

    Inside C:\Rtools\gcc-4.6.3\bin64 there is a file called 'gdb.exe'.

    When i execute this file a session (very similar to cmd) opens:


    Of course i can navigate to this path using a normal cmd session:


    What can i do now? if try R CMD INSTALL from this way i get a (until now unknown) 😉 error message: 'no executable specified use 'target exec'

    Another question in the system variable Path: there are lowercase c´s:

    c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin;C:\Program Files\R\R-2.15.0\bin\x64

    could this be a problem? In the meantime i switched it to capital C´s but without succes:-(

    New Guru ideas are very welcome;-)

    Thanks in advance


    • Hi Marcel -

      I think the problem centres around the fact that you do not seem to be building RSAP.dll ?

      What output do you get when you run:

      R CMD INSTALL --build --preclean --clean --no-multiarch -l C:/<your RSAP source directory> RSAP


      Piers Harding.

    • Marcel:

      Welcome back 🙂're executing the gdb file by double clicking on it...and then calling it by navigating to the path...but what about calling it from C:/?

      Like C:\>gdb

      Does it open it?

      Having "c" or "C" should't affect the that's not it...

      So...if you do R CMD INSTALL you get an error saying "no executable specified use 'target exec"? I got Error: ERROR: no packages specified...

      If you get the first means that your command line is not grabbing "gdb" which is the compiler...



      Development Culture.

  • Hey Piers,

    yes this is the problem it centres arround, you are absolutely right!

    My RSAP source directory is C:/RSAP/src. In this directory there are all the necessary files.

    I get the following, independend if i try it with:

    C: R CMD INSTALL --build --preclean --clean --no-multiarch -l C:/RSAP/src RSAP


    C: R CMD INSTALL --build --preclean --clean --no-multiarch -l C:/RSAP/ RSAP


    C:\RSAP\ R CMD INSTALL --build --preclean --clean --no-multiarch -l C:/RSAP/src RSAP


    C:\RSAP\ R CMD INSTALL --build --preclean --clean --no-multiarch -l C:/RSAP/ RSAP

    its always:


    The translation from german to english would be:

    'Warning: invalid package 'RSAP'

    Error: Error: no packages specified(or indicated)

    Thank you again!!!


    • OK - so what happens if you cd into C:\RSAP and then run:

      R CMD INSTALL --build --preclean --clean --no-multiarch .

      remember the "dot" on the end.



  • Hey Blag,

    when i am executing it from C:\ i get:


    This means:

    The command "gdb" is either written in the wrong way or couldn´t be found.

    If I open the gdb.exe via double click and then type 'R CMD INSTALL' i get:


    If i open a normal cmd session and type 'R CMD INSTALL' i get:



    • Well...that's actually a way 😛 As it confirms that your system is not getting the right path for "gdb" to work...which is also weird as you have it on your path...

      And I have it the same way c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin; on System Variables --> Path...and it's callable from the command line...




      Development Culture.

  • Good morning Piers,

    if i navigate to C:/RSAP and type R CMD INSTALL --build --preclean --clean --no-multiarch .

    I get the same error message:


    The translation from german to english would be:

    'Warning: invalid package '.'

    Error: Error: no packages specified(or indicated)

    Greetings Marcel

  • Hello and good morning Blag,

    I don´t know if thats 'actually good' 😉

    But you are right we know now at least one thing which doesnt work as it should.

    What do you think, does it make sense to try the whole build with the latest R-Version and the corresponding Rtools Version?

    By the way I have a Windows 7 Service Pack 1, 64bit System.

    And another thing i just saw: we some differences in out gdb Versions i suppose:


    Whereas in your screenshot is:


    could that be another problem?

    Have a nice day!


  • Hey Piers,

    yes I think you are right the build environment is obviously broken:-(

    I copied the source code from your page 1:1 and saved it in a .c file called RSAP.c

    I don´t think that a mistake happend by copying the file from the web to my local RSAP.c but of course i will double-check it this evening.

    Can you imagine why the build environment could be broken? Or do you have a hint how to reinstall/repair it?

    Have a nice day!


  • Hello again Gurus,

    i am still struggeling but have not resigned until now 🙂

    Good news / findings /Question marks 😕 :

    1. gdb now works from the command line. The reason why it didn´t work before was, that the standard installation of Rtools editet the system-variable path to:


    but the gdb.exe is loacated here in (my 215) RTools version


    therefore the compiler couldn´t work. I switched the systemvariable, respectivly added a new vale C:\Rtools\gcc-4.6.3\bin64 and now gdb works in every folder.

    @Blag: I am still wondering how your gdb is able to work if the gdb.exe is not located there where the path variable points to. I installed the Rtools215.exe from here:

    Building R for Windows 

    and than it creates the following folder structure:


    2. In Piers RSAP.c source code he includes (amongst other things):

    #include <R_ext/PrtUtil.h>

    #include <R_ext/Rdynload.h>

    due to Blags advice i got rid of the sub folder R_ext. So i have edited the source code to

    #include <PrtUtil.h>

    #include <Rdynload.h>

    3. The other libs:

    #include <stdio.h>

    #include <stdlib.h>

    #include <stdio.h>

    #include <sys/types.h>

    #include <fcntl.h>

    #include <string.h>

    #include <limits.h>

    are not located in C:/RSAP/src. But i think that are standart c libs and the compiler can magically find them?!

    4. On the Rtools page i found "changes since R 2.15.1:

    " The bitmap libraries have been updated to jpeg-8d, libpng 1.5.12, and libtiff 4.0.2. The Cygwin tools have been updated to versions current as of July 13, 2012. NB: some of the tools now require you to have a HOME environment variable, listing your home directory. One way you can create it in a Windows command shell is by using

    set HOME=%USERPROFILE%  Rtools 2.15 has been frozen"

    Although i use the R 2.15.0 Version  i think this is related to the corresponding Rtools version. So I have created the HOME variable and set it to C:/RSAP

    5. On Piers page i found the "configure-files":


    Due to nescience i preventivly added the files to my C:/RSAP/src

    With the feeling of a little progress the error messages are unfortunatly the same:-(

    Althoug i found the documentation of "R CMD INSTALL"

    R: Install Add-on Packages

    here and experimented a bit with it, i am still not successfull in compiling the RSAP package...

    Do you have further advice for me? Or will RSAP remain a phantom? 😆

    kind regards


  • Hello, excuse me for annoying you again, but i can´t believe that i dont get the thing up and running. And i think the only chance is to solve it with your Guru help.;-)

    1. What i found respectivly understood in Piers Changelog was that the has to be part of the package.

    So i changed the third line to: nwrfcsdk="C:/RSAP/src" because here are the nwrfcsdk components loacated.

    2. Meanwhile I am not sure anymore if the components of the nwrfcsdk relly have to be in the C:/RSAP/src folder. Because when I look to Piers documentation and to the first version of Blags there was always the path C:/nwrfcsdk. Of course i tried already all permutations without success.

    Can you please give me an advice how to proceed or what to check now?

    Thank you soooo much in advance!


  • Hello everyone,

    First of all I'd like to thank you all for getting me this far. Unfortunately if i'm posting today it's because somehow it doesn't quite work for me either.

    The package RSAP seemed to have compiled correctly, but whatever I tried in RSAPConnect (whether or not I use a .YML file does not change anything) command, the R session crashes. I am absolutely not sure what could cause such issue. I'm not able to have a log or anything that could help debug this before crashing, and of course I've tried a lot of arguments in that command to try and make it run.

    I'm not even sure if i should have my SAP up and running authenticated under my credentials, or not to make this work.

    Could you please provide me with some guidance on how i should proceed in debugging and understanding what's going on ?