R CMD INSTALL卡在一个起作用的函数上...如何进一步调试此函数? [英] R CMD INSTALL is stuck on a function that works... how can I debug this further?

查看:107
本文介绍了R CMD INSTALL卡在一个起作用的函数上...如何进一步调试此函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:问题说明中的许多信息都是无关紧要的,并且已经通过解决方案中列出的调试步骤以没有明显原因的方式解决了问题部分

note: much of the information in the problem statement is irrelevant, and the problem has been resolved with no apparent reason through the debugging steps that are listed in the resolution section

对于造成我无法复制的错误的问题,我深表歉意.

问题

我的程序包"PKG"中有一个测试函数"foo.R"; foo.R包含:

I have a test function 'foo.R' in my package 'PKG'; foo.R consists of:

foo <- function (filename, n) {
  text <- scan(file = filename, what = "character")
  if (n==1) text <- gsub("\\#GGG", '\\#', text)
  if (n>1)  text <- gsub("\\#GGG", '', text)
  writeLines(text, con = 'newfn.R')
}

foo的目的是在n> 1时通过用"替换"#GGG"来取消注释行,或者在n == 1时使行注释掉

The intent of foo is to either uncomment lines by replacing "#GGG" with "" when n>1 or to leave the line commented if n == 1

产生此错误所需的最少代码是:

The minimal code required to produce this error is:

foo <- function (string) {
    gsub("\\#GGG", '', string)
}

但是,当我运行R CMD INSTALL PKG时,出现以下错误:

However, when I run R CMD INSTALL PKG I get the following error:

Error in parse(outFile) : 
  /tmp/RtmpLbFQF0/R.INSTALL2edd9a07/PKG/R/foo.R:3:1: unexpected '}'
2:   gsub("\\#GGG", '\\#', string)
3: }
   ^

更新

  1. 根据答案,"\#"不是罪魁祸首.

  1. Based on the answers, '\#' is not the culprit.

我发现问题出在安装过程中(而非内部版本),并且我更改了问题以反映这一点.我还修复了测试用例中的花括号.

I have found that the problem is during install (not build), and I have changed the question to reflect this. I have also fixed the curly braces from my test case.

此外,我发现该功能不仅有效,例如加载source()时,

Also, I have found that not only does the function work, e.g. when loaded with source(),

  • 当我创建一个新项目(例如"newproject")并将功能移到那里时,它会正确安装,即可以正常工作:

  • When I make a new project (e.g. 'newproject') and move the function there, it installs without error, i.e. this works:

  1. 将foo.R移至newproject/R/foo.R
  2. 创建新项目/说明
  3. R CMD建立新项目
  4. R CMD安装新项目

  • 这给出了上面的错误:

  • This gives the error above:

    1. R CMD建立PKG
    2. R CMD安装PKG

  • 响应对错误输出日志的请求,R CMD check PKG的输出与R CMD INSTALL PKG的错误相同,

    In response to the request for the error output log, the output from R CMD check PKG is the same as the error from the R CMD INSTALL PKG,

    • 安装 source 软件包"PKG" ... ** R parse(outFile)中的错误:/home/user/PKG/R/foo.R:24:0: 输入22的意外结束:
      writeLines(model.text,con = outfile) 23:} ^错误:无法整理 软件包"PKG"的文件
    • 删除"/home/user/PKG.Rcheck/PKG"
    • installing source package ‘PKG’ ... ** R Error in parse(outFile) : /home/user/PKG/R/foo.R:24:0: unexpected end of input 22:
      writeLines(model.text, con = outfile) 23: } ^ ERROR: unable to collate files for package ‘PKG’
    • removing ‘/home/user/PKG.Rcheck/PKG’

    解决方案

    错误的解决方法是无法解释的,但是我在两个具有相同错误的函数上重现了相同的看似神奇的方法.

    The resolution of the error is inexplicable, but I reproduced the same seemingly magical method on two functions with the same error.

    1. mv /PKG/R/foo.R PKG/foo.R
    2. 在emacs中访问新的PKG/R/foo.R
    3. 用于(i在函数的其他位中
    1. mv /PKG/R/foo.R PKG/foo.R
    2. Visit new PKG/R/foo.R in emacs
    3. for (i in misc bits of function
    1. 剪切并粘贴我
    2. R CMD check PKG
    3. 如果PKG可以安装
    4. 返回到1
    5. 否则删除位并返回到3
    1. cut-and-paste i
    2. R CMD check PKG
    3. if PKG can install
    4. return to 1
    5. else remove bits and return to 3

  • diff PKG/foo.R PKG/R/foo.R
  • 如果没有区别,除了该功能现在可以使用

  • diff PKG/foo.R PKG/R/foo.R
  • if no difference except that function now works

    1. 更新关于SO的问题
    2. 考虑以前的错误是偶然的事情
    3. 继续进行,好像什么都没发生

  • 更新2:发现罪魁祸首!

    问题是在函数之前的注释符号##的左侧出现了错误的"e"

    UPDATE 2: culprit found!

    The problem was an errant 'e' stuck to the left of the comment symbols ## coming before a function

    推荐答案

    否,R抱怨是因为没有开头{

    NO, R is complaining because there's no opening {

    foo <- function(string){   
     gsub(blah)
    }
    

    打开卷曲,关闭卷曲.

    这篇关于R CMD INSTALL卡在一个起作用的函数上...如何进一步调试此函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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