利用 reticulate
接口,我们可以在 R
中调用 python
封装的函数。
环境变量
1
2
|
export LD_LIBRARY_PATH=/home/ops/anaconda3/lib:/shared/trading/lib/gcc/lib64:/shared/trading/lib:/shared/trading/lib/gcc9/lib64:/shared/trading/lib/gcc9/lib:${LD_LIBRARY_PATH}
export PATH=/shared/trading/lib/gcc/bin:/shared/trading/lib/binutils/bin:/shared/trading/lib/gcc9/bin:${PATH}
|
修改 Make
1
2
3
4
5
6
7
8
9
10
11
12
13
|
mkdir -p ~/.R
vim ~/R/Makevars
CC = /shared/trading/lib/gcc9/bin/gcc
CXX = /shared/trading/lib/gcc9/bin/g++
CXXSTD = -std=c++11
CXXFLAGS = -g -O3 -Wall -fPIC -pipe -Wno-unused -pedantic -static-libgcc -static-libstdc++
LD_LIBRARY_PATH = /shared/trading/lib/gcc9/lib64:/shared/trading/lib/gcc9/lib:$LD_LIBRARY_PATH
CPLUS_INCLUDE_PATH = /shared/trading/lib/gcc9/include:$CPLUS_INCLUDE_PATH
#CXX17 = g++-7 -std=gnu++17 -fPIC CXX11 = g++
CXX14 = g++
CXX17 = g++
CXX17STD = -std=c++17
|
安装 reticulate
1
2
|
install.packages("https://cran.r-project.org/src/contrib/Archive/reticulate/reticulate_1.25.tar.gz", repos=NULL, type="source")
install.packages("https://cran.r-project.org/src/contrib/Archive/RcppTOML/RcppTOML_0.1.3.tar.gz", repos=NULL, type="source")
|
使用
1
2
3
4
5
6
|
library(reticulate)
use_python("~/miniconda3/bin/python")
source_python('/fs/public/ops/config/ceph.py')
dt <- read_s3_csv('raven/futures_minute/prod/trade_config/GTJA_ZGC_SHFE/2024-11-28.csv')
print(dt)
|