Skip to content

pymetrix-r

A plugin: a separate package

pymetrix-r is a first-party plugin, installed on its own (not yet on PyPI: from a clone of the repository):

python -m pip install -e packages/pymetrix-r

R scripts into pymetrix: a readable script, a report with a row per line, and the same work as recorded steps (no R needed). Not affiliated with or endorsed by the R Foundation.

The names pymetrix_r exports (its __all__), with their full documentation. Import them from the plugin: from pymetrix_r import .... The plugin's README says more.

Public names

ATTACHMENTS module-attribute

ATTACHMENTS = 'pymetrix-r'

FIXEST_VCOV module-attribute

FIXEST_VCOV = ('cluster', 'iid')

LANGUAGE module-attribute

LANGUAGE = 'R'

parse_r

parse_r(text: str) -> Program

An R script read into top-level statements, each with its tree or why it does not parse; a statement that does not parse ends at the next line that starts at the top level, so every line still gets a row.

Program dataclass

Program(source: str, lines: tuple[str, ...], statements: tuple[RStatement, ...], comments: dict[int, str] = dict())

An R script read: its text, lines, statements and each line's comment (by line, without the #).

read_dta

read_dta(path: str, *, time: str | None = None, entity: object = None, freq: str | None = None, start: str | None = None, **kw: object) -> object

A Stata file (.dta), read by pandas with its numbers kept as numbers (value labels are not applied, as haven's read_dta keeps the codes); time, entity, start and freq as for a CSV file.

RECORDED_BY module-attribute

RECORDED_BY = 'r:script'

RParseError

RParseError(message: str, line: int, col: int = 0)

Bases: PyMetrixError

A line of R that does not parse: line and col (from 1) say where.

RTranslation dataclass

RTranslation(script: str, report: TranslationReport, program: str = '', ops: Sequence[Any] = (), functions: Sequence[Any] = (), objects: Mapping[str, Any] = dict(), arguments: Mapping[str, str] = dict(), sources: Mapping[str, str] = dict(), script_lines: Mapping[Any, int] = dict())

Bases: Translation

An R script translated (translate_r): script, readable Python that uses pymetrix's public API; report, a row per line (translated, translated with a note, left out, or error, with the reason); and run(session), the same work as recorded steps (recorded as r:script; the script and the report kept in the project under pymetrix-r).

translate_r

translate_r(source: Any, data: Any = None, *, read_options: Any = None, folder: Any = None, fixest_vcov: str = 'cluster') -> RTranslation

An R script translated: .script (readable Python), .report (a row per line: translated, translated with a note, left out or error, with the reason) and .run(session) (steps mode).

source is the script's text, or the path of a .R file. data maps the files its read.csv lines read (the path as written, or its file name) to where they are now; without it a path is read as written, from the script's folder (folder, default the script's own). read_options gives Dataset.read's options for a file, by the same key ({"wages.csv": {"entity": "id"}}): which column identifies the rows, or start and freq; where the script does not say (ts, pdata.frame) and they are not given, they are guessed from the file's first rows, as File > Load data does. fixest_vcov is what feols does without vcov=: "cluster" (by the first fixed effect, fixest's default up to version 0.12) or "iid"; the translation always writes the covariance out.

Plugin plumbing

What pymetrix's plugin loader reads (PLUGIN, register) and the plugin's version.

__version__ module-attribute

__version__ = '0.1.0a1'

PLUGIN module-attribute

PLUGIN = PluginInfo(name='pymetrix-r', version=__version__, api='1.13', license='BSD-3-Clause', maintainer='Geoffrey Heenan', description='R scripts translated into readable pymetrix scripts, with a report on every line and the same work as recorded steps; no R needed')

register

register() -> None

The entry point (pymetrix.plugins, pymetrix.io): .dta files read through read_dta and the help topic. Importing the package registers them too; a second call does nothing.