Phil
Phil

Reputation: 23

RMarkdown Octave Plot

Can RMarkdown produce plots when using Octave for its engine? Here's a basic example:

```{octave}
plot([1,2,3])
```

In CoCalc, as in Octave and MATLAB, the output would be a plot. Similarly, when using the R engine in RMarkdown for

```{r}
plot(c(1,2,3))
```

I would like to be able to do this for Octave in RMarkdown - is there a solution for this?

Upvotes: 2

Views: 394

Answers (1)

danlooo
danlooo

Reputation: 10627

Octave's function plot does not return an image, but opens a window instead. This is why it also doesn't work on R Studio Server by default. Here is a workaround by using print() and displaying the image afterwards:

---
title: "Untitled"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  echo = TRUE,
  engine.path = list(
    octave = "/usr/bin/octave"
  )
)
```

```{octave}
plot([1,2,3])

print("file.png")
```

![](file.png)

enter image description here

Upvotes: 2

Related Questions