This post shows a R counterpart of Excel VBA’s MSXML2.ServerXMLHTTP related commands with which server APIs are called easily. In case of R, it is done by using httr R package. As an illustration, SQL query for retrieving swap date schedule is executed by calling this server API.
Calling Server API in a simple manner
This post is simple and provides a Excel VBA code and the corresponding R code for calling SQL query indirectly by using web server API. Sample SQL returns some swap schedule as an example. In the two codes below, the server URL address is not a valid address since it is just for illustration purpose.
You can just copy and paste the necessary part for your purpose.
Excel VBA : MSXML2.ServerXMLHTTP
The following Excel VBA code uses MSXML2.ServerXMLHTTP object to do the above job. Of course, specific parts depend on in-house system.
Running the above Excel macro returns the following output.
R code with httr package
The following R code uses httr R package to do the above same job.
In the above R code, it is worth noting that a SQL query string is inserted as a member of list. Running this R code returns the following same output.
As we call server API function using MSXML2.ServerXMLHTTP in Excel VBA, we can also do the same job by using httr package. \(\blacksquare\)