从r包中提取源代码 [英] extracting source code from r package

查看:506
本文介绍了从r包中提取源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安装r软件包,但是很遗憾,它太旧了,无法在新版本的r中实现.

I am trying to install the r package sowas and unfortunately it is too old to implement in the new versions of r.

根据作者的说法,您可以使用source()函数使用该程序包来访问代码,但是我无法弄清楚该怎么做.

According to the author you can use the package using the source() function to gain access to the code but I have not been able to figure out how to do that.

感谢您的帮助.

这里是我描述的软件包的链接,因为它不是CRAN软件包: http://tocsy.pik-potsdam.de/wavelets/

Here is a link to the package I described as it is not a CRAN package: http://tocsy.pik-potsdam.de/wavelets/

推荐答案

.zip文件是Windows二进制文件,因此不会太有趣.您将要看的是.tar.gz归档文件的内容.您可以提取这些内容,然后查看R子目录中的代码.

The .zip file is a windows binary and as such it won't be too interesting. What you'll want to look at is the contents of the .tar.gz archive. You can extract those contents and then look at the code in the R subdirectory.

您还可以更新软件包以使其与R的新版本一起使用,以便您可以实际构建和安装该软件包.为此,您可以像以前一样解压缩.tar.gz的文件,但现在您需要添加一个NAMESPACE文件.这只是软件包目录顶部的纯文本文件,其格式如下:

You could also update the package to work with new versions of R so that you can actually build and install the package. To do so you could unpack the .tar.gz as before but now you'll need to add a NAMESPACE file. This is just a plaintext file at the top of the package directory that has a form like:

export(createar)
export(createwgn)
export(criticalvaluesWCO)
export(criticalvaluesWSP)
export(cwt.ts)
export(plot.wt)
export(plotwt)
export(readmatrix)
export(readts)
export(rk)
export(wco)
export(wcs)
export(writematrix)
export(wsp)

对于要实际使用的包中的任何功能,您都有导出语句的位置.如果未导出功能,则程序包中的功能仍然可以访问该功能,但用户无法使用它(很容易).完成后,您应该可以构建和安装该软件包.

Where you have an export statement for any function in the package that you actually want to be able to use. If a function isn't exported then the functions in the package still have access to that function but the user can't use it (as easily). Once you do that you should be able to build and install the package.

我已经自由地做了一些这样的事情.我实际上并没有花时间确定哪些功能有用并且应该导出,只是假设如果为该功能编写了帮助页面,而没有帮助页面,那我就没有了.出口.我使用Rd2roxygen将帮助页面转换为roxygen代码(因为这就是我滚动的方式),之后不得不进行一些清理,但似乎安装得很好.

I took the liberty of doing some of this already. I haven't actually taken the time to figure out which functions are useful and should be exported and just assumed that if a help page was written for the function that it should be exported and if there wasn't a help page then I didn't export it. I used Rd2roxygen to convert the help pages to roxygen code (because that's how I roll) and had to do a little bit of cleanup after that but it seems to install just fine.

因此,如果您安装了devtools软件包,则实际上应该可以使用以下命令安装直接修改的版本

So if you have the devtools package installed you should actually be able to install the version I modified directly by using the following commands

library(devtools)
install_github("SOWAS", "Dasonk")

我个人建议您使用添加NAMESPACE文件的方法,而不是直接添加的方法,这样您将对代码有更多的控制权,并能够解决使用软件包时可能出现的任何问题.或者,如果您使用git,则可以派生我的仓库,并从那里继续修复问题.祝你好运.

Personally I would recommend that you go the route of adding the NAMESPACE file and what not directly as then you'll have more control over the code and be more able to fix any problems that might occur when using the package. Or if you use git you could fork my repo and continue fixing things from there. Good luck.

这篇关于从r包中提取源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆