我正在 RStudio 平台上开发一个 R 包。我有许多用 python 编写的函数,我想用 R 调用它们。现在我刚刚为 DNA 序列实现了一个简单的反向补码函数。在 RStudio 上编写和构建项目时,代码运行良好。一旦我在 github 上发布它并从 repo 安装到其他机器上,它就会成功安装,但是当我调用该函数时它无法运行。详情如下图所示:
$猫rev.py
def revcompl (s):
rev_s = ''.join([{'M':'M', 'A':'T','C':'G','G':'C','T':'A'}[B] for B in s][::-1]).replace ("CM","MG")
return rev_s
$ cat reverse_complement.R
#' Reverse complement for a given DNA sequence
#'
#' \code{reverse_complement} Reverse complement of a DNA sequence
#'
#' @usage reverse_complement (sequence)
#'
#' @param sequence A DNA sequence
#' @export
#'
reverse_complement <- function(sequence) {
revFile = system.file("python", "rev.py", package = "rpytrial")
print (revFile)
python.load(revFile)
rev_strand = python.call ("revcompl", sequence)
return (rev_strand)
}
执行 install_github 后,当我运行 reverse_complement("AAAAA") 时,出现以下错误:
[1] ""
File "<string>", line 3
except Exception as e:_r_error = e.__str__()
^
IndentationError: expected an indented block
Error in python.exec(python.command) : name 'revcompl' is not defined
In addition: Warning message:
In file(con, "r") :
file("") only supports open = "w+" and open = "w+b": using the former
从错误中我可以说它没有找到路径。但是有没有办法解决它?
谢谢,萨蒂亚