RMarkdown中的Python

时间:2018-02-24 16:06:36

标签: python r-markdown

我试图在RMarkdown中执行Python。虽然代码块使用运行当前块按钮单独执行时输出完全正常,但在编织文档时却没有执行。下面是代码块的简单复制

q

以下是我收到的错误消息

void bisector_of_lines(const double &pa, const double &pb, const double &pc, const double &qa, const double &qb, const double &qc, double &a, double &b, double &c) { // We normalize the equations of the 2 lines, and we then add them. double n1 = sqrt(pa*pa + pb*pb); double n2 = sqrt(qa*qa + qb*qb); a = n2 * pa + n1 * qa; b = n2 * pb + n1 * qb; c = n2 * pc + n1 * qc; // Care must be taken for the case when this produces a degenerate line. if (a == 0 && b == 0) {// maybe it is best to replace == with https://stackoverflow.com/questions/19837576/comparing-floating-point-number-to-zero a = n2 * pa - n1 * qa; b = n2 * pb - n1 * qb; c = n2 * pc - n1 * qc; } }

我甚至尝试将{python engine.path='~/anaconda3/bin/python3',python.reticulate=F} x=[1,2,3] print(x) 添加到running: ~/anaconda3/bin/python3 -c ' x=[1,2,3,4] print(x)' Quitting from lines 14-17 (Error_demo.Rmd) Error in system2(cmd, code, stdout = TRUE, stderr = TRUE, env = options$engine.env) : error in running command Calls: <Anonymous> ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous> Execution halted 文件中,如this问题的回复中所述。但这似乎也无济于事。有人可以告诉我,我做错了什么?

1 个答案:

答案 0 :(得分:0)

这应该做(对我有用):

library(reticulate)
knitr::knit_engines$set(python = reticulate::eng_python)

详情here