简体   繁体   English

更改R包中的功能并在Ubuntu上安装

[英]making change to function in R package and installing on Ubuntu

Short question: I want to edit the postgresqlWriteTable function in the RPostgreSQL package and install it on R running on an Ubuntu machine. 简短的问题:我想编辑RPostgreSQL包中的postgresqlWriteTable函数并将其安装在运行Ubuntu机器的R上。

Long explanation: 详细说明:

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. 我的问题的根源在于,我试图使用RPostgreSQL包中的dbWriteTable ,使用R中的自动递增主键列写入postgres表。

I read this post: How do I write data from R to PostgreSQL tables with an autoincrementing primary key? 我读了这篇文章: 如何使用自动递增的主键将数据从R写入PostgreSQL表? which suggested a fix to my problem by changing the function postgresqlWriteTable in the RPostgreSQL package. 它通过更改RPostgreSQL软件包中的函数postgresqlWriteTable提出了解决我的问题的建议。 It works when I interactively use fixInNamespace in OSX environment and edit the function. 当我在OSX环境中以交互方式使用fixInNamespace并编辑该功能时,它将起作用。

Unfortunately I have to run my script on an AWS instance running R on Ubuntu. 不幸的是,我必须在Ubuntu上运行R的AWS实例上运行脚本。 I have RPostgreSQL installed at this location on my machine: /usr/local/lib/R/site-library/RPostgreSQL . 我在RPostgreSQL上的以下位置安装了RPostgreSQL/usr/local/lib/R/site-library/RPostgreSQL I installed it by invoking R CMD install RPostgreSQL_0.4-1.tar.gz 我通过调用R CMD install RPostgreSQL_0.4-1.tar.gz安装了它

Now I am trying to find the function postgresqlWriteTable . 现在,我试图找到函数postgresqlWriteTable It is supposed to be in the file PostgreSQLSupport.R . 它应该在文件PostgreSQLSupport.R I have searched the whole library - there is no such file. 我已经搜索了整个库-没有这样的文件。

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. 我意识到在OSX Finder的本地计算机上,当我解压缩tar.gz软件包文件夹时,可以看到文件PostgreSQLSupport.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 然后,我从Ubuntu机器中删除了已安装的RPostgreSQL,并将新文件夹(从本地机器)复制到Ubuntu机器中,并尝试使用devtools来安装软件包,如本文中的建议: 从自定义目录加载R软件包

here's what happened: 这是发生了什么:

> 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)

I am at my wit's end ! 我没办法 !

  1. Copy the pacakge .tar.gz file to the AWS machine. 将pacakge .tar.gz文件复制到AWS机器上。
  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. 您可能还必须增加DESCRIPTION文件中的版本号。
  5. Use devtools::build to create a new .tar.gz file. 使用devtools::build创建一个新的.tar.gz文件。
  6. Install this updated version of the package. 安装此更新版本的软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM