更改R包中的功能并在Ubuntu上安装 [英] making change to function in R package and installing on Ubuntu

查看:86
本文介绍了更改R包中的功能并在Ubuntu上安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短的问题:我想编辑 RPostgreSQL 包中的 postgresqlWriteTable 函数并将其安装在R

Short question: I want to edit the postgresqlWriteTable function in the RPostgreSQL package and install it on R running on an Ubuntu machine.

长解释:

我的问题的根源是我正在尝试使用 RPostgreSQL 中的 dbWriteTable 从R中自动写入主键列的Postgres表包。

The root of my problem is that I am trying to write to a postgres table with an auto-incrementing primary key column from R using dbWriteTable from RPostgreSQL package.

我读了这篇文章:如何使用自动递增的主键将R中的数据写入PostgreSQL表?这建议解决我的问题通过更改 RPostgreSQL 包中的函数 postgresqlWriteTable 解决问题。当我在OSX环境中交互式使用 fixInNamespace 并编辑该功能时,它可以工作。

I read this post: How do I write data from R to PostgreSQL tables with an autoincrementing primary key? which suggested a fix to my problem by changing the function postgresqlWriteTable in the RPostgreSQL package. It works when I interactively use fixInNamespace in OSX environment and edit the function.

不幸的是,我必须在Ubuntu上运行R的AWS实例上运行脚本。我在计算机上的以下位置安装了 RPostgreSQL / usr / local / lib / R / site-library / RPostgreSQL 。我通过调用 R CMD install RPostgreSQL_0.4-1.tar.gz

Unfortunately I have to run my script on an AWS instance running R on Ubuntu. I have RPostgreSQL installed at this location on my machine: /usr/local/lib/R/site-library/RPostgreSQL . I installed it by invoking R CMD install RPostgreSQL_0.4-1.tar.gz

安装了找到函数 postgresqlWriteTable 。它应该在文件 PostgreSQLSupport.R 中。我已经搜索了整个库-没有这样的文件。

Now I am trying to find the function postgresqlWriteTable. It is supposed to be in the file PostgreSQLSupport.R . I have searched the whole library - there is no such file.

我意识到在OSX Finder的本地计算机上,当我解压缩tar.gz软件包文件夹时,可以看到文件 PostgreSQLSupport。 R 应该在其中更改功能的地方。

I realized that on my local machine in the OSX Finder , when I unzip the tar.gz package folder, I can see the file PostgreSQLSupport.R where I am supposed to change the function.

所以我更改了功能。然后,我从Ubuntu机器中删除了已安装的RPostgreSQL,并将新文件夹(从本地机器)复制到了Ubuntu机器中,并尝试使用 devtools 来安装软件包,如此处的帖子:从自定义目录加载R包

So I changed the function. Then I removed the installed RPostgreSQL from my Ubuntu machine and copied the new folder (from my local machine) into my Ubuntu machine and tried to use devtools to install the package as suggested in the post here: Loading an R Package from a Custom directory

这是发生了什么:

> library("devtools")
> install("/usr/local/lib/R/site-library/RPostgreSQL")
Error: Can't find '/usr/local/lib/R/site-library/RPostgreSQL'.
> install("RPostgreSQL", "/usr/local/lib/R/site-library/RPostgreSQL")
Installing RPostgreSQL
'/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet  \
  CMD INSTALL '/datasci/nikhil/RPostgreSQL'  \
  --library='/usr/local/lib/R/site-library' --install-tests 

* installing *source* package ‘RPostgreSQL’ ...
file ‘R/PostgreSQLSupport.R’ has the wrong MD5 checksum
ERROR: 'configure' exists but is not executable -- see the 'R Installation and Administration Manual'
* removing ‘/usr/local/lib/R/site-library/RPostgreSQL’
Error: Command failed (1)

我机智了!

推荐答案


  1. 复制pacakge .tar.gz 文件到AWS机器。

  2. 解压缩该文件,使您具有目录结构。

  3. 在文件内编辑函数并保存更改。

  4. 您可能还必须增加 DESCRIPTION 文件中的版本号。

  5. 使用 devtools :: build 创建一个新的 .tar.gz 文件。

  6. 安装此更新版本的包。

  1. Copy the pacakge .tar.gz file to the AWS machine.
  2. Unpack this file so you have a directory structure.
  3. Edit the function inside the file and save your changes.
  4. You may also have to increase the version number in the DESCRIPTION file.
  5. Use devtools::build to create a new .tar.gz file.
  6. Install this updated version of the package.

这篇关于更改R包中的功能并在Ubuntu上安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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