Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with multiple statements python chunks from file #1589

Closed
Atrebas opened this issue Jun 22, 2019 · 5 comments
Closed

Error with multiple statements python chunks from file #1589

Atrebas opened this issue Jun 22, 2019 · 5 comments
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@Atrebas
Copy link

Atrebas commented Jun 22, 2019

The following code works when code2 contains a single statement.
It fails if it contains multiple statements, that otherwise are executed correctly if provided directly in the Rmd document.
Both cases work fine with R.

---
output: html_document
---


```{r}
library(knitr)

# works with a single statement
# cat("## @knitr  code2\nprint(1+1)", file = 'file.py', append = FALSE)

# fails with multiple statements
cat("## @knitr  code2\nprint(1+1)\nprint(1+1)", file = 'file.py', append = FALSE)

read_chunk('file.py')
```

```{python}
print(1+1)
print(1+1)
```


```{python}
<<code2>>
```

The error is:

Quitting from lines 25-26 (tmp.Rmd) 
Error in py_call_impl(callable, dots$args, dots$keywords) : 
  SyntaxError: multiple statements found while compiling a single statement (<string>, line 1)
Calls: <Anonymous> ... <Anonymous> -> py_compile_eval -> <Anonymous> -> py_call_impl
Execution halted

Thanks.

Locale:
  LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
  LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
  LC_TIME=English_United States.1252    

Package version:
  base64enc_0.1.3  digest_0.6.19    evaluate_0.14    glue_1.3.1       graphics_3.3.2   grDevices_3.3.2 
  highr_0.8        htmltools_0.3.6  jsonlite_1.6     knitr_1.23       magrittr_1.5     markdown_1.0    
  methods_3.3.2    mime_0.7         Rcpp_1.0.1       rmarkdown_1.13.4 stats_3.3.2      stringi_1.4.3   
  stringr_1.4.0    tinytex_0.13     tools_3.3.2      utils_3.3.2      xfun_0.7         yaml_2.2.0      

Pandoc version: 2.3.1

I understand that my issue may be closed if I don't fulfill my promises.

@yihui yihui added the bug an unexpected problem or unintended behavior label Jun 22, 2019
@yihui yihui added this to the v1.14 milestone Jun 22, 2019
@yihui
Copy link
Member

yihui commented Jun 22, 2019

Fixed in knitr. You can install the development version via

remotes::install_github('yihui/knitr')

Thanks for the report!

@Atrebas
Copy link
Author

Atrebas commented Jun 22, 2019

Thanks for the quick fix! Sorry for the confusion with knitr.

@Atrebas
Copy link
Author

Atrebas commented Jun 22, 2019

Me again. FYI, there is an error when python chunks contain comments only.

---
output: html_document
---

# ok

```{python}
# comment
1
```

# ko

```{python}
# comment
```
Error in mapply(c, starts, ends, SIMPLIFY = FALSE) : 
  zero-length inputs cannot be mixed with those of non-zero length
Calls: <Anonymous> ... block_exec -> in_dir -> engine -> <Anonymous> -> mapply
Execution halted

@yihui
Copy link
Member

yihui commented Jun 24, 2019

Please see yihui/knitr#1724 (comment)

clrpackages pushed a commit to clearlinux-pkgs/R-knitr that referenced this issue Aug 9, 2019
Darío Hereñú (1):
      Fixed syntax issues (#1725)

Emily Riederer (1):
      cleaned up sass dependency following sass CRAN release (#1722)

Yihui Xie (14):
      start the next version
      input can no longer be connections
      all-in on UTF-8!
      cosmetic
      roxygenize and bump version
      remove "above"
      fix rstudio/rmarkdown#1589: parse_chunk() no longer concatenate source lines to a single string by \n
      clean up files/dirs written by examples since CRAN will NOTE them
      input must be character if provided
      Revert "cleaned up sass dependency following sass CRAN release (#1722)"
      fix broken links
      use xvfb-run; I don't know why "sh -e /etc/init.d/xvfb start" stopped working on Travis
      also clean up the figure/ dir here
      CRAN release v1.24

atusy (1):
      travis ci depends on libglu1-mesa-dev (#1727)
@github-actions
Copy link

github-actions bot commented Nov 3, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants