Skip to content

mrpg/r-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

r_snippets

The file preload.R contains some useful R snippets that I have developed over time. This set of snippets makes serious use of R almost possible. This set of snippets is bound to be enhanced and amended over time. Feel free to just copy that file into your own R project. You can load it like this:

source("preload.R")

These snippets default to HC3 standard errors. (Note: Stata defaults to HC1 standard errors, which are not recommended.)

Example

See example.R.

This file also shows a feature of these snippets that is frequently missed: save_to saves your LaTeX regression table to a file. This means that within your paper, you can do

\input{output/table1.tex}

No more copy and pasting! Crucially, the file name is determined automatically from your list of models.

Dependencies

R

To use all the functions in preload.R, you need these R packages:

  1. texreg, preferably as found here¹
  2. lmtest
  3. sandwich

¹ You can use install.packages("remotes"); remotes::install_github("mrpg/texreg_fork") to install that.

LaTeX

When using tt(), include these LaTeX packages:

\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{microtype}
\usepackage{siunitx}
\usepackage{threeparttable}

License

Code: This R code is licensed under the GNU General Public License v3.0 (GPL-3.0). See LICENSE for details. Note that there is absolutely no warranty.

Why GPL? Unfortunately, because preload.R uses GPL-licensed R packages (texreg, lmtest, and sandwich), the code must be GPL-licensed due to the copyleft requirement. This is a regrettable constraint imposed by dependencies stemming from an unfortunate norm within the R community to prefer the GPL over the LGPL.

Data licensing recommendation: While this code (and your code using it!) must be GPL, you should license your data under CC0 1.0 (see ./LICENSE-DATA). Data and code are separate works and can have different licenses. Always put as much as possible under CC0, especially data. This maximizes reusability and exceeds best practices for scientific reproducibility.

How to License Your Data Under CC0

Follow the Social Science Data Editors licensing guidance. For repositories containing both code and data:

  1. Download CC0 license: Download LICENSE-DATA from this repository or run curl -o LICENSE-DATA https://creativecommons.org/publicdomain/zero/1.0/legalcode.txt on your computer.

  2. Specify which files are dual-licensed using glob patterns in README.md. Example:

## License

All files in this repository are licensed under the [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.html) (GPL-3.0). See `LICENSE` for full legal text. Note that there is **absolutely no warranty**.

## Data files

The following files are **dual-licensed under GPL-3.0 AND CC0 1.0** (you may choose either license):

- `*.csv`
- `*.dta`
- `*.json`
- `*.RData`
- `*.rds`
- `*.tsv`
- `*.xlsx`

This dual-licensing means you can use these data files under the maximally permissive CC0 public domain dedication if you prefer. See `LICENSE` (GPL-3.0) and `LICENSE-DATA` (CC0) for full legal texts.
  1. Keep code under GPL by maintaining separate LICENSE (GPL) and LICENSE-DATA (CC0) files.

This "globbing method" ensures maximum reusability: your data gets the most permissive license (CC0) while code respects GPL dependencies. See the Greenelab example for a complete implementation (with different licenses).

About

Simple R snippets to make R barely usable

Resources

License

GPL-3.0, CC0-1.0 licenses found

Licenses found

GPL-3.0
LICENSE
CC0-1.0
LICENSE-DATA

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages