Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating MATLAB scripts into R Markdown Document

I would like to integrate some old matlab scripts into an .Rmd document for my thesis to avoid the copy-pasting that knitr tries to avoid anyways. Is this possible? Using http://yihui.name/knitr/demo/engines/ I was able to integrate python code no problem, but matlab is a lot more difficult.

like image 728
yakzo Avatar asked May 08 '14 09:05

yakzo


2 Answers

knitr has been updated and actual version, 1.15.1, allows more supported engines: octave is one of them:

library(knitr)
names(knit_engines$get())

 [1] "awk"       "bash"      "coffee"    "gawk"      "groovy"   
 [6] "haskell"   "lein"      "mysql"     "node"      "octave"   
[11] "perl"      "psql"      "python"    "Rscript"   "ruby"     
[16] "sas"       "scala"     "sed"       "sh"        "stata"    
[21] "zsh"       "highlight" "Rcpp"      "tikz"      "dot"      
[26] "c"         "fortran"   "fortran95" "asy"       "cat"      
[31] "asis"      "stan"      "block"     "block2"    "js"       
[36] "css"       "sql" 

To add octave code in a Rmarkdown notebook use:

```{octave}
# Insert your octave code here
```
like image 132
Enrique Pérez Herrero Avatar answered Sep 28 '22 02:09

Enrique Pérez Herrero


The currently supported engines by knitr are

> require(knitr);
names(knit_engines$get())
 [1] "awk"       "bash"      "coffee"    "gawk"      "haskell"   "perl"      "python"    "Rscript"    "ruby"      "sas"      
[11] "sed"       "sh"        "zsh"       "highlight" "Rcpp"      "tikz"      "dot"       "c"         "asy"       "cat"

So yes, matlab is not currently supported as knitr engine but maybe this (Convert MATLAB code to R) could help in porting matlab code to R

like image 41
Silence Dogood Avatar answered Sep 28 '22 03:09

Silence Dogood