help for importr

Import R data files into Stata via R or Python

importr
using filename
[, clear rds]

Description

importr (v2.0.0) provides a robust bridge to import R data files (.Rdata, .Rda, .Rds)
into Stata. It uses a dual-bridge architecture to ensure compatibility across
different system environments.

How it Works

The command follows a two-step fallback logic:

1. R Bridge: It first attempts to call Rscript. If found, it uses
R and the haven package to convert the data.

2. Python Bridge: If R is not found, it attempts to use Stata's internal
python integration and the pyreadstat library.

Standalone Utilities

For users working outside of Stata, this package also includes standalone
Python utilities (RtoStata.py and pythontoR.py) for bi-directional
conversion between R and Stata formats. See the README.md for details.

Requirements

To use the R Bridge (Default):

- R and Rscript must be in your system's PATH.

- R package haven must be installed.

To use the Python Bridge (Fallback):

- Stata 16 or newer.

- Python library pyreadstat must be installed.

- Installation command: python pip install pyreadstat

Options

clear clears any data currently in Stata's memory before importing.

rds specifies that the source file is an RDS file. Usually detected
automatically.

Examples

Import an R workspace file (tries R first, then Python):

. importr using "mydata.Rdata", clear

Import an RDS file:

. importr using "results.rds", clear

Author

Eric A. Booth

eric.a.booth@gmail.com

http://www.eric-booth.com

Also see

On-line: help for import, python, shell