microsoft / RTVS

R Tools for Visual Studio.
MIT License
390 stars 118 forks source link

Params not found when running notebook chunk #4227

Open Lugribossk opened 6 years ago

Lugribossk commented 6 years ago

Please briefly describe what you were doing that led to the issue, if applicable: Running a chunk in a notebook that uses params does not work, while previewing it does. For example this notebook (I had to remove the last ` to get the quoting to work):

---
title: "Params test"
output: html_document
params:
  name: world
---

```{r}
paste("Hello", params$name)
``

If I right-click the chunk and select "Run current chunk" the preview window will show an error saying Error in paste("Hello", params$name) : object 'params' not found. However clicking "Preview HTML" will produce an html file that says "Hello world", an opening the notebook in R Studio and running the chunk will also correctly print "Hello world".

If you have any screenshots demonstrating the issue, please include them as well to help us diagnose it better.

Additional information:

OS Information Version: Microsoft Windows NT 10.0.16299.0

RTVS Information: Assembly: Microsoft.VisualStudio.R.Package, Version=1.2.30905.1244, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Active R URI: Microsoft R Open (3.4.2.0): C:\Program Files\Microsoft\R Open\R-3.4.2\

MikhailArkhipov commented 6 years ago

This is because rendering session does not know about declaration in the markdown title section. This needs to be implemented. Workaround is to declare object in a special {r} block somewhere in the beginning of the file instead.

cosmin-novac commented 5 years ago

This is because rendering session does not know about declaration in the markdown title section. This needs to be implemented. Workaround is to declare object in a special {r} block somewhere in the beginning of the file instead.

This doesn't make sense, using "params" in the title sections is the only way to pass parameters to knit, is it not?