An open API service indexing awesome lists of open source software.

https://github.com/ropensci/gitignore

A R interface to fetch gitignore templates form gitignore.io
https://github.com/ropensci/gitignore

Last synced: 5 months ago
JSON representation

A R interface to fetch gitignore templates form gitignore.io

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# gitignore

[![CRAN status](https://www.r-pkg.org/badges/version/gitignore)](https://cran.r-project.org/package=gitignore)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Codecov test coverage](https://codecov.io/gh/ropensci/gitignore/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ropensci/gitignore?branch=main)
[![DOI](https://zenodo.org/badge/184759416.svg)](https://zenodo.org/badge/latestdoi/184759416)
[![rOpenSci peer-review](https://badges.ropensci.org/303_status.svg)](https://github.com/ropensci/software-review/issues/303)
[![R-CMD-check](https://github.com/PMassicotte/gitignore/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ropensci/gitignore/actions/workflows/R-CMD-check.yaml)

Based on the definition proposed by [freecodecamp](https://www.freecodecamp.org/news/gitignore-what-is-it-and-how-to-add-to-repo/):

> The .gitignore file is a text file that tells Git which files or folders to ignore in a project. A local .gitignore file is usually placed in the root directory of a project. You can also create a global .gitignore file and any entries in that file will be ignored in all of your Git repositories.

For any project, it is therefore important to have a `.gitignore` file that is complete and accurate. The package `gitignore` provides a simple R interface to the [gitignore.io](https://www.toptal.com/developers/gitignore) API. It can be used to fetch gitignore templates that can be included into the `.gitignore` file of you git repository. The `gitignore` R package can be used with R package, R Studio project or with any `.gitignore` file. Note that by default, the `usethis` package populates the `.gitignore` for the R language when you create a R project. However, it is common to use many different programming languages in a project such as `LaTeX`, `python`, `matlab`, `julia` and so one. This is where the `gitignore` package shines as it can be used to programmatically modify the `.gitignore` file of your project.

## Installation

The CRAN version of `gitignore` can be installed using:

```{r, eval=FALSE}
install.packages("gitignore")
```

The dev version of `gitignore` can be installed from GitHub:

```{r, eval=FALSE}
install.packages("devtools")
devtools::install_github("ropensci/gitignore")
```

## Examples

There are currently two useful functions in the package:

- `gi_available_templates()` to fetch all supported gitignore templates.
- `gi_fetch_templates()` to fetch one or many gitignore templates.

Show the first 25 templates returned by `gi_available_templates()`.

```{r}
library(gitignore)

head(gi_available_templates(), 25)
```

Templates can be fetched using the `gi_fetch_templates()` function.

```{r, results='markup', comment=""}
gi_fetch_templates("R")
```

Multiple templates can be fetched by specifying multiple values:

```{r, results='markup', comment=""}
gi_fetch_templates(c("java", "c++"))
```

By default, templates are copied into the clipboard. It is also possible to modify a `.gitignore` file using the `gi_write_gitignore()` function.

```{r, eval=FALSE}
f <- file.path(tempdir(), ".gitignore")
new_lines <- gi_fetch_templates("r")
gi_write_gitignore(fetched_template = new_lines, gitignore_file = f)
```

If `gitignore_file` is not specified, `gitignore` will try to find the `.gitignore` file of your current project or package.

More examples are provided in the vignette.

```{r, eval=FALSE}
browseVignettes("gitignore")
```

You can also visit the [gitignore website](https://docs.ropensci.org/gitignore/).

## Code of conduct

Please note that the 'gitignore' project is released with a [Contributor Code of Conduct](https://docs.ropensci.org/gitignore/CODE_OF_CONDUCT.html). By [contributing to this project](https://docs.ropensci.org/gitignore/CONTRIBUTING.html), you agree to abide by its terms.

[![ropensci_footer](https://ropensci.org/public_images/ropensci_footer.png)](https://ropensci.org)