---
title: "Interacting with the R Session"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Interact with the R Session}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(eval = FALSE)
```

The `rstudioapi` package allows you to interact with the running R session in a couple useful ways: you can send code to the R console, or restart the R session.

```{r}
# restart R, then run some code after
rstudioapi::restartSession(command = "print('Welcome back!')")

# send some code to the console and execute it immediately
rstudioapi::sendToConsole("1 + 1", execute = TRUE)
```

