Markdown-preview-enhanced: Rmorkdown

Created on 14 Mar 2018  路  3Comments  路  Source: shd101wyy/markdown-preview-enhanced

I like you package, Congratulation.
I am using R and Python, as you know we can run codes inside .Rmd file,
see
https://rwebapps.ocpu.io/markdownapp/www/

Unfortunately, your package can not run codes. I am wondering if you have plan to add this feature to your package.

Most helpful comment

This is indeed an issue, because this extension requires the file to be printed to stdout. However,
it seems that Rscript cannot do that easily.
Using this solution one can force the files to be printed to stdout.

` R {cmd="Rscript"}
dev_stdout = function (underlying_device = svg, ...) {
filename = tempfile()
underlying_device(filename, ...)
filename
}
dev_stdout_off = function (filename) {
dev.off()
on.exit(unlink(filename))
fake_stdout = pipe('cat', 'wb')
on.exit(close(fake_stdout), add = TRUE)
writeBin(readBin(filename, 'raw', file.info(filename)$size), fake_stdout)
}

tmp_dev = dev_stdout()
plot(iris)
dev_stdout_off(tmp_dev)
```
````

All 3 comments

Running code chunks in markdown-preview-enhanced is supported, although with a slightly different syntax. What could be improved?

Wonderful, good job.

There are two issues,
1) It does not show plot of R?
2) The new chunk, rerun new Rscript, so does not load the codes that already run in the previous chuck.
see below.

The Normal Distribution

```R {cmd="/usr/local/bin/Rscript"}
output <- rnorm(30);
output
hist(output)

The normal distribution has the typical bell shape:

```Rscript {cmd="/usr/local/bin/Rscript"}
output

This is indeed an issue, because this extension requires the file to be printed to stdout. However,
it seems that Rscript cannot do that easily.
Using this solution one can force the files to be printed to stdout.

` R {cmd="Rscript"}
dev_stdout = function (underlying_device = svg, ...) {
filename = tempfile()
underlying_device(filename, ...)
filename
}
dev_stdout_off = function (filename) {
dev.off()
on.exit(unlink(filename))
fake_stdout = pipe('cat', 'wb')
on.exit(close(fake_stdout), add = TRUE)
writeBin(readBin(filename, 'raw', file.info(filename)$size), fake_stdout)
}

tmp_dev = dev_stdout()
plot(iris)
dev_stdout_off(tmp_dev)
```
````

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ckdanny picture ckdanny  路  5Comments

yushukk picture yushukk  路  3Comments

liuwa666 picture liuwa666  路  5Comments

lambdafu picture lambdafu  路  3Comments

StefanoCecere picture StefanoCecere  路  5Comments