zoukankan      html  css  js  c++  java
  • R语言调用C函数

    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 中运行

  • 相关阅读:
    windows下编译Boost库
    linux下编译Boost库
    CEPH安装教程(下)
    CEPH安装教程(中)
    CEPH安装教程(上)
    nfs使用教程
    iscsi使用教程(下)
    POJ-2096 Collecting Bugs 概率dp
    HDU-3586 Information Disturbing 树形dp+二分
    HDU-1024 Max Sum Plus Plus 动态规划 滚动数组和转移优化
  • 原文地址:https://www.cnblogs.com/lmj-sky/p/10308988.html
Copyright © 2011-2022 走看看