我正在嘗試使用rpython從R調用python。很棒。現在我試圖將我的R代碼安裝到一個有4個不同蟒蛇的碼頭集裝箱中。原來configure script允許你指定python版本(RPYTHON_PYTHON_VERSION),但不是Python的路徑。從R調用Python的rpython替代方案?
那麼,是否有另一個R包來從R調用Python?
我正在嘗試使用rpython從R調用python。很棒。現在我試圖將我的R代碼安裝到一個有4個不同蟒蛇的碼頭集裝箱中。原來configure script允許你指定python版本(RPYTHON_PYTHON_VERSION),但不是Python的路徑。從R調用Python的rpython替代方案?
那麼,是否有另一個R包來從R調用Python?
可以使用R的system2函數執行它作爲子進程執行並捕獲輸出。
來自R執行Python腳本的一個例子:
# run_splitstr.R
command = "python"
# Note the single + double quotes in the string (needed if paths have spaces)
path2script='"path/to your script/splitstr.py"'
# Build up args in a vector
string = "3523462---12413415---4577678---7967956---5456439"
pattern = "---"
args = c(string, pattern)
# Add path to script as first arg
allArgs = c(path2script, args)
output = system2(command, args=allArgs, stdout=TRUE)
print(paste("The Substrings are:\n", output))
要捕捉字符向量(每個元素一行)標準輸出,由於輸出= TRUE必須在系統2中指定,否則就在出口狀態被返回。當stdout = TRUE時,退出狀態被存儲在一個名爲「status」的屬性中。
謝謝,這是合理的。我想調用一個Python函數,而不是一個過程,但也許我必須縮減和改變。 – dfrankow
@hrbrmstr這是一個非常蹩腳的被動積極迴應,但如果您提交它作爲答案,我會接受它。特別是,我嘗試了網狀,看起來很不錯。 – dfrankow