R 2.14.0源碼中有函數 massdist.c 函數,在 R 3.5.1 中該函數發生了改變,但是有一個軟件包 kerfdr 需要調用 2.14.0 中的該 C 函數,為了便於后續程序的發展。
現欲將 老版本的 massdist.c ( 從R 2.14.0 源碼中找到 massdist.c 修改名為 massdistnew.c ,內部函數命名為masstest.c) 函數轉移到 R 3.5.1中:
1:安裝 Rtools
2:安裝 mingw
3 : 將Rtools 安裝文件中的bin 以及mingw的 bin 文件添加到環境變量中
4:在R語言中運行下面兩行代碼生成dll文件
setwd("H:/test/Rcpp_test")
system("R CMD SHLIB massdistnew.c")
5:載入dll文件
dyn.load('H:/test/Rcpp_test/massdistnew.dll')
6: 在調用函數時原始的調用方式為:
# mass distribution according to tau y = .C("massdist", x = as.double(xtrunc), xmass = as.double(tau[trunc]/sum(tau[trunc])), nx = nx, xlo = as.double(lo), xhi = as.double(up), y = double(2 * n), ny = as.integer(n), PACKAGE = "stats")$y
修改為:
dyn.load('H:/test/Rcpp_test/massdistnew.dll') y = .C("massdisttest", x = as.double(xtrunc), xmass = as.double(tau[trunc]/sum(tau[trunc])), nx = nx, xlo = as.double(lo), xhi = as.double(up), y = double(2 * n), ny = as.integer(n))$y
以上處理之后kerfdr即可在 R 3.5.1 中運行