---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

# setup-r

[![RStudio community](https://img.shields.io/badge/community-github--actions-blue?style=social&logo=rstudio&logoColor=75AADB)](https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions)

This action sets up an R environment for use in actions by:

- Downloading and caching a version of R by version and adding to PATH
- Registering [problem matchers](https://github.com/r-lib/actions/tree/v2/setup-r/.github) for error output
- Setting the following environment variables
  - `NOT_CRAN=true`
  - `TZ=UTC`
  - `R_LIBS_USER=tempdir/Library`
  - `_R_CHECK_SYSTEM_CLOCK_=FALSE`
- Removing the `-fopenmp` flags from Makeconf on macOS, which are not supported
  with Apple's default Command Line Tools compilers.
- Appending 'on GitHub Actions' to the default HTTP user agent. This is useful to
  distinguish GitHub Actions package requests from other sources.
- Supplying the installed R version as a `installed-r-version` output.

## Inputs

```{r, echo = FALSE, results = "asis"}
action <- yaml::read_yaml("action.yml")
action_df <- tibble::tibble(
  name = names(action$inputs),
  description = purrr::map_chr(action$inputs, "description"),
  default = purrr::map_chr(action$inputs, ~ if (is.logical(.x$default)) if (isTRUE(.x$default)) "true" else "false" else glue::single_quote(.x$default))
)
cat(glue::glue_data(action_df, "- **{name}** (`{default}`) - {description}"), sep = "\n")
```

## Outputs

- **installed-r-version** - The full R version installed by the action

## Usage

Basic:
```yaml
steps:
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-r@v2
  with:
    r-version: '3.5.3' # The R version to download (if necessary) and use. 
    # Use "renv" to retrieve R version recorded in renv.lock file.
- run: Rscript -e 'print("hello")'
```

Matrix Testing:
```yaml
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        R: [ '3.5.3', '3.6.1' ]
    name: R ${{ matrix.R }} sample
    steps:
      - uses: actions/checkout@v3
      - name: Setup R
        uses: r-lib/actions/setup-r@v2
        with:
          r-version: ${{ matrix.R }}
      - run: Rscript -e 'print("hello")'
```

## FAQ

### How do I use a custom R profile that sets an option?

You can add an extra step to your workflow, after R was installed,
and create the R profile. Here is an example:
```yaml
      - name: Add some R options for later steps
        run: |
          cat("\noptions(tinytex.verbose = TRUE)\n", file = "~/.Rprofile", append = TRUE)
        shell: Rscript {0}
```

## License

The scripts and documentation in this project are released under the [MIT License](LICENSE)

## Contributions

Contributions are welcome!
