knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-"
)

SPQR

Govern your calls in R with SPQR.

knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(out.width='750px', dpi=200)

Overview

This package is about manipulating calls in handy ways. It contains four main functions, S, P, Q, and R.

These functions are intended to be useful in experimental R-work, such as simulations, trying out new algorithms, messing around with different models, et cetera.

Installation

From inside R, use one of the following commands:

# For the development version from GitHub:
# install.packages("devtools")
devtools::install_github("JonasMoss/SPQR")

Usage

The R function

The R function can be used for simulations in this way.

library("SPQR")
n = 100
sim = R(data.frame(y = 5 + 3*x1 + 6*x2 + rnorm(n),
                  x1 = rnorm(n),
                  x2 = rnorm(n)))
lm(y ~ x1 + x2, data = sim)

Without the R function, we typically have to do something like

n = 100
y = 5 + 3*x1 + 6*x2 + rnorm(n)
x1 = rnorm(n)
x2 = rnorm(n)
df = data.frame(y = y, x1 = x1, x2 = x2)
lm(y ~ x1 + x2, data = df)

But this messes up your namespace, as it makes three new useless variables y, x1, and x2, variables you don't really need. In addition, if any of these variables are already present in your namespace, they are overwritten. This is a hassle, and can create hard-to-understand bugs.

Another handy example is printing. When doing exploratory data analysis, I find myself in need of ploting things again and again. With R, I can do the following:

R(plot(x = seq(-1, 1, by = 0.01), dnorm(x, 0, 3)))


JonasMoss/SPQR documentation built on Oct. 30, 2019, 7:58 p.m.