MUCollective / multiverse

R package for creating explorable multiverse analysis
https://mucollective.github.io/multiverse/
GNU General Public License v3.0
62 stars 5 forks source link

Create custom code chunk type for rmarkdown in rstudio #6

Closed mjskay closed 4 years ago

mjskay commented 5 years ago

After #2 is done, we can look into creating a custom code chunk type for markdown. Perhaps something like this:

```{multidy optional_chunk_name, multiverse = M}
df = some_code_to_create_df()
df
```

Which would be compiled into something like this:

```{r optional_chunk_name}
inside(M, {
  df = some_code_to_create_df()
  df
})
```

Then we could even create an addin + keyboard shortcut for RStudio to create these code chunks (much like there is a keyboard shortcut for creating R code chunks). Would want to make sure that autocomplete still works for these.

abhsarma commented 5 years ago

output for other types:

Parsing expressions:

abhsarma commented 5 years ago

Not sure how to write unit tests for this. Any suggestions?

mjskay commented 5 years ago

Ah, hrm. Dunno. There might be some ways of doing it by calling knitr functions directly? You could look at how the rmarkdown package does it?

mjskay commented 5 years ago

Also, if you haven't already, this might be a case where seeing if it is even possible first is a good idea before writing tests... I have a feeling doing this in a seemless way inside rstudio might actually be hard or even impossible currently (at least, having the custom code chunk type work like r code with autocomplete and all that). Unless you've already figured that out?

abhsarma commented 5 years ago

Not sure I get the autocomplete part --- what do you mean?

mjskay commented 5 years ago

like, having rstudio actually treat the code chunk as if it is an R code chunk when you are editing the code, so that it does nice things like lets you use autocomplete, does syntax highlighting, and formats outputted tables as interactive widgets and the like.

abhsarma commented 5 years ago

I am not sure about the formatting of tables, but it does still autocomplete and highlights the syntax by default

mjskay commented 5 years ago

huh cool. can you get it to run R code inside Rstudio if you write a bare-bones chunk type that's called "multidy" ?

abhsarma commented 5 years ago

Yeah. I think I committed this to the dev branch. It's in the Rmd file. Like, if I have a code chunk called multidy and run some code into it, it will run it inside the multiverse

mjskay commented 5 years ago

I get this error trying to load the multidy package on dev:

Loading multidy
Error in eval(exprs[i], envir) (from eng_multidy.R#1) : object 'knit_engines' not found
mjskay commented 5 years ago

if I load knitr it works but it doesn't display the output of the code chunk, it displays a number?

e.g. I would expect this to output the data frame from the current universe:

```{multidy, multiverse = M}
df
```

but it outputs this:

101
mjskay commented 5 years ago

I also get weird issues with multiline code chunks:

```{multidy, multiverse = M}
x = 5
x + 1
```
Error in parse(text = x) : <text>:1:6: unexpected symbol
1: x = 5x
         ^