JuliaInterop / JuliaCall

Embed Julia in R
https://non-contradiction.github.io/JuliaCall/index.html
Other
267 stars 36 forks source link

don't know how to handle 'julia' engine output #98

Closed Boylad closed 5 years ago

Boylad commented 5 years ago

sessionInfo() R version 3.5.2 (2018-12-20) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale: [1] LC_COLLATE=Chinese (Simplified)_China.936 LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936

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

other attached packages: [1] JuliaCall_0.16.5

loaded via a namespace (and not attached): [1] compiler_3.5.2 tools_3.5.2 yaml_2.2.0 Rcpp_1.0.1 knitr_1.22
[6] xfun_0.5

image

Non-Contradiction commented 5 years ago

Is this in RStudio's notebook? I think the Julia engine is not supported yet.

kongdd commented 5 years ago

The same problem in RStudio

Non-Contradiction commented 5 years ago

Yes, currently RStudio notebook does not support JuliaCall yet. I will dig into this at my spare time. Thank you for the feedback!

Non-Contradiction commented 5 years ago

Okay, I think I have found out the root of the problem, actually two problems here. The first one is that in the RStudio notebook, JuliaCall does not think it is running in a document generation environment, so it does not do some necessary settings. The second one is that the RStudio notebook simply abandons the output generated by JuliaCall, which is kind of weird because the output generated by JuliaCall is in a standard structure for knitr and RMarkdown.

Before I proceed to the solution of the problem, @kongdd would you help me check whether the solution is correct or not? Before running the julia chunk, first run an R chunk like this:

```{r}
julia <- JuliaCall::julia_setup()
parent.env(julia)$rmd <- TRUE
JuliaCall::julia_command("Base.pushdisplay(JuliaCall.rmd_display);")
ojulia <- JuliaCall::eng_juliacall
njulia <- function(...) paste0(ojulia(...), collapse = "\n")
knitr::knit_engines$set("julia" = njulia)

And see if the problem in running julia chunks exists or not.
kongdd commented 5 years ago

Great. This setting works

a = sqrt(2)
print(a)
## 1.4142135623730951

## 1.4142135623730951
Non-Contradiction commented 5 years ago

The problem should be fixed on JuliaCall master. So before the execution of any Julia chunk, you should call JuliaCall::julia_notebook_setup() to do the initial setup for the notebook.

Non-Contradiction commented 4 years ago

The julia_notebook_setup function is replaced by the julia_markdown_setup(notebook = TRUE) in the new release 0.17.1, and now the setup for the notebook should be invoked automatically most of the time, so no need to invoke explicitly.