Closed Boylad closed 5 years ago
Is this in RStudio's notebook? I think the Julia engine is not supported yet.
The same problem in RStudio
Yes, currently RStudio notebook does not support JuliaCall yet. I will dig into this at my spare time. Thank you for the feedback!
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.
Great. This setting works
a = sqrt(2)
print(a)
## 1.4142135623730951
## 1.4142135623730951
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.
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.
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