rrstudioreprex

How to run reprex in Rstudio? I encountered an error


after installation the package,

> library(reprex)
> (y <- 1:4)
[1] 1 2 3 4
> mean(y)
[1] 2.5
> reprex()
Rendering reprex...
Error: callr subprocess failed: <text>:18:7: unexpected 'in'
17: #+ reprex-body
18: Error in
          ^

Solution

  • I can't tell for sure, but it looks like you might be running code in the console and then running reprex(). Instead, do one of the following

    1. Place your code inside the reprex function:

      reprex({
        (y=1:4)
        mean(y)
      })
      

      You can do this directly in the console or in a script file in the RStudio "source" pane. Then run the code.

    2. Type your code in an R script file in the RStudio source pane:

      (y=1:4)
      mean(y)
      

      Then copy it to the clipboard. Then run reprex() in the console.

    Either way, you should then see the following in the Viewer pane. The output below will also have been placed in your clipboard, so that you can paste it into any other location:

    enter image description here