home

SWire4R documentation


Introduction

Swire4R is an R package for exchanging data between R and Stata. SWire4R uses SWire for connecting R to Stata. SWire is a plugin for Stata >=13 which acts like a server: client applications can query SWire for interacting with Stata. SWire4R acts like a client application for Swire, providing the user with various basic functions for retrieving data from Stata and exporting data to Stata. SWire4R must be compiled by R. This document will illustrate how to compile SWire4R for Linux and Mac (compiling instructions for Windows are not provided).


SWire4R at a glance

Suppose you load the auto.dta dataset in Stata:

sysuse auto

You wish to obtain the "price" variable in R: load the SWire4R library in R and call the swire.getNumericVar function:

> library(SWire4R)
> swire.getNumericVar("price")
$status
[1] 0

$data
 [1]  4099  4749  3799  4816  7827  5788  4453  5189 10372  4082 11385 14500
[13] 15906  3299  5705  4504  5104  3667  3955  3984  4010  5886  6342  4389
[25]  4187 11497 13594 13466  3829  5379  6165  4516  6303  3291  8814  5172
[37]  4733  4890  4181  4195 10371  4647  4425  4482  6486  4060  5798  4934
[49]  5222  4723  4424  4172  9690  6295  9735  6229  4589  5079  8129  4296
[61]  5799  4499  3995 12990  3895  3798  5899  3748  5719  7140  5397  4697
[73]  6850 11995

The swire.getNumericVar returns a list with two components. The status component is an integer number, which is zero in the case of no error in executing the request; the data component is a vector containing the data from the "price" variable.


Requirements

Swire4R requires Swire and SWire requires Stata >= 13. In order to compile the package in Linux and Mac, the msgpack-c library (https://github.com/msgpack/msgpack-c) and the development files for libcurl (https://curl.haxx.se/libcurl/) are required. See below for installation instructions.


Installation

Linux and Mac OS X

In order for R to compile the package on Linux and Mac, msgpack-c (https://github.com/msgpack/msgpack-c) and development files for libcurl (https://curl.haxx.se/libcurl/) are required.

The following are the commands for installing the msgpack-c library onto your system:

git clone https://github.com/msgpack/msgpack-c.git
cd msgpack-c cmake . 
make sudo install

Mac OS X has a copy of libcurl in one of its system folders, so installation is not required. The libcurl development files can be installed in Linux (Debian distributions) by typing the following command:

sudo apt-get install libcurl4-gnutls-dev

Open R and type the following command to install the SWire4R package:

install.packages("/path_to_swire4r/SWire4R_0.1.tar.gz", repos=NULL, type="source")

where path_to_swire4r is the folder containing the SWire4R_0.1.tar.gz file. If the installation was successful, you can load the package by typing the following in R:

library("SWire4R")

Prior to using SWire4R, do not forget to activate SWire in Stata. Load Stata and type:

swire start

Now return to R and use SWire4R.

Windows

No documentation is provided for Windows in this document.


Reference

A PDF reference manual (SWire4R-manual.pdf) is shipped with the ZIP file which includes SWire4R.


Also see

SWire
A software interface, enabling us to query Stata for the executing of basic operations, such as reading or writing data

2016 Italian Stata Users Group Meeting, Rome 17-18 November
Abstract and slides presented at the Italian Stata Users Group Meeting 2016

SWire Web Apps Collection
A collection of web apps, interacting with Stata through SWire

SWire4js
A JavaScript library for developing SWire web applications

Swire4QGIS
A QGIS plugin enabling data exchange with Stata

SQuery
A web application for collecting questionnaires' responses in Stata


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.