2

I'm new to targets ecosystem. I could not create a distill article from my targets pipeline although it works when I set the output to html_document in yaml. I have tried googling but couldn't find anything useful. Any help would be appreciated.

My RStudio is version 1.4.1717. I got this error message upon running tar_make():

Error: callr subprocess failed: Distill articles cannot be previewed in this version of RStudio.
Please update to version 1.2.718 or higher at https://www.rstudio.com/products/rstudio/download/

Visit https://books.ropensci.org/targets/debugging.html for debugging advice.
Run `rlang::last_error()` to see where the error occurred.

Here is a minimal code example.

Code in _targets.R

library(targets)
library(tarchetypes)

tar_plan(
  tar_target(dat, iris),
  tar_render(test_report, "test.Rmd")
)

Here are the contents of my Rmd file. Most of them are from the template.

---
title: "Test"
description: |
  A new article created using the Distill format.
author:
  - name: Nora Jones 
    url: https://example.com/norajones
    affiliation: Spacely Sprockets
    affiliation_url: https://example.com/spacelysprokets
date: "`r Sys.Date()`"
output: distill::distill_article
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

```{r load-targets, include=FALSE}
tar_load(dat)
```

```{r}
summary(dat)
```

Session info

R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] igraph_1.2.6      rstudioapi_0.13   knitr_1.33        magrittr_2.0.1    tidyselect_1.1.1 
 [6] R6_2.5.1          rlang_0.4.11      fansi_0.5.0       tools_4.1.0       targets_0.7.0    
[11] data.table_1.14.0 xfun_0.25         utf8_1.2.2        cli_3.0.1         withr_2.4.2      
[16] ellipsis_0.3.2    yaml_2.2.1        digest_0.6.27     tibble_3.1.3      lifecycle_1.0.0  
[21] crayon_1.4.1      processx_3.5.2    purrr_0.3.4       callr_3.7.0       vctrs_0.3.8      
[26] ps_1.6.0          codetools_0.2-18  glue_1.4.2        compiler_4.1.0    pillar_1.6.2     
[31] pkgconfig_2.0.3  
Zaw
  • 1,434
  • 7
  • 15
  • It's hard to say why you are getting that error, I cannot reproduce it locally. But maybe your system is finding an old version of the RStudio IDE. If you have old versions of the IDE, I suggest removing them and trying again. Also, do you get the same error if you avoid `targets` and just just call `rmarkdown::render("test.Rmd")` in the console manually? (Note: this is different from the Knit button, which has its own way of working.) – landau Aug 23 '21 at 11:55
  • Thank you for looking into it. I don't have any older version of RStudio IDE installed in my system. `rmarkdown::render("test.Rmd")` ran successfully. – Zaw Aug 23 '21 at 13:15

1 Answers1

1

I've been having the same issue.

From here you can see that distill checks for the version first by trying the rstudioapi (which fails) and then by looking for an environment variable called "RSTUDIO_VERSION", which does not exist on my system. When this fails, it uses a default value of 1.1, which fails the check of having at least version 1.2.7...

There is a simple, if slightly hacky, solution which is to just manually set the environment variable that distill is looking for at the top of your script. I.e., your Rmd file would become:

---
title: "Test"
description: |
  A new article created using the Distill format.
author:
  - name: Nora Jones 
    url: https://example.com/norajones
    affiliation: Spacely Sprockets
    affiliation_url: https://example.com/spacelysprokets
date: "`r Sys.Date()`"
output: distill::distill_article
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
# Add environment variable
Sys.setenv("RSTUDIO_VERSION" = '1.4.1725')
```

```{r load-targets, include=FALSE}
tar_load(dat)
```

```{r}
summary(dat)
```

This works totally fine for me. If you're worried about this having ongoing effects, you can remove it afterwards (Sys.unsetenv("RSTUDIO_VERSION"))

Taren Sanders
  • 421
  • 2
  • 12