R .gitignore template
The R template ignores the saved workspace, command history, package check output and rendered documents, including one file that stores real OAuth credentials.
At a glance
- Category
- Language
- Patterns in this template
- 17 rules
- Directories ignored
- 5 of the 17 rules end in a slash, so they match directories only
- Also needs an OS template
- Yes. Nothing here matches file manager artefacts, which turn up in data directories.
- Typical companions
- An editor template. R work often mixes with notebooks, so consider that one too.
In detail
.RData is the saved workspace: every object in memory when the session ended, serialised to disk. Committing it is a common accident with real consequences, because a workspace saved during analysis contains whatever data was loaded, which may be the confidential dataset the repository was carefully written to keep out. It is also the reason results become irreproducible, since a stale workspace silently supplies objects the script no longer creates.
.Rhistory and .Rapp.history are the command histories from the console and the macOS application. .Ruserdata holds per user session state. All three record what one person typed, which is neither shared knowledge nor reproducible input. A history file is also a good record of the paths and connection strings someone worked with, so it leaks a little about the machine it came from as well as adding noise.
.httr-oauth is the one to take seriously. It caches OAuth tokens obtained during an interactive authentication, so it contains live credentials for whatever service you connected to. A committed copy hands anyone with repository access the same API access you have, and unlike a password it is easy to miss in review because the filename looks like configuration.
The package check rules cover /*.Rcheck and /*.tar.gz, both anchored to the root, which is where the check tooling writes its output and the source tarball it builds. *-Ex.R is the extracted example script from the same process. .Rproj.user is the editor's per project working directory.
The rendering rules cover vignettes/*.html and vignettes/*.pdf, plus *.utf8.md and *.knit.md, which are the intermediate markdown files produced while knitting a document. The cache rules /*_cache and /cache cover chunk caches, which are keyed to the exact code that produced them and become misleading the moment the code changes.
Examples
.Rhistory
.Rapp.history
.RData
.Ruserdata
*-Ex.R
/*.tar.gz
/*.Rcheck/
.Rproj.user/
vignettes/*.html
vignettes/*.pdf
.httr-oauth
/*_cache/
/cache/
*.utf8.md
*.knit.md
rsconnect/
inst/doc17 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- If .RData was committed before the template was added, the data inside it is in the history of every clone. Treat it the way you would a leaked credential rather than as a tidy up job.
- .httr-oauth holds working tokens. Ignoring it is necessary but not sufficient: revoke and reissue anything that was ever committed.
- inst/doc is ignored without a trailing slash, so a file of that name would match as readily as the directory. In practice it is always a directory, but the asymmetry is worth knowing.
Try it: .gitignore Generator
Pick one or more templates, tick the common additions you want, and copy or download the combined .gitignore.
.gitignore Generator
LOCAL · Browser-OnlyGenerate comprehensive .gitignore files by combining templates for languages, frameworks, IDEs, and operating systems
Language
Framework
IDE
OS
Build Tool
Infrastructure
Common Additions
Preview
Select templates or common additions to generate a .gitignore file.
Related .gitignore templates
All .gitignore templates →Jupyter Notebook .gitignore template
The Jupyter template ignores autosave checkpoints and profile folders, but the real problem with notebooks in git is the output cells, which no rule fixes.
Python .gitignore template
A line by line read of the Python .gitignore template: bytecode caches, virtual environments, packaging output, test caches and the lib/ rule that bites.
macOS .gitignore template
Where .DS_Store actually comes from, why it appears in folders nobody edited, and what the rest of the macOS template covers on network and removable volumes.
Lua .gitignore template
A short template for a short toolchain: compiled bytecode from luac, packaged rock archives, and the local tree LuaRocks installs dependencies into.
Perl .gitignore template
The Perl template ignores the build library tree, generated metadata and coverage output, and its Makefile rule will also match a Makefile you wrote yourself.
Haskell .gitignore template
What the Haskell template covers: object and interface files, the dist output directories, profiling and event log output, and the local project overrides.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS