I am developing a R package on RStudio platform. I have many functions written in python which I want to call using R. For now I just implemented a simple reverse complement function for a DNA sequence. While writing and building the project on RStudio, the code works fine. Once I release it on github and install on other machine from the repo, it successfully installs, but when I call the function it fails to run. The details are shown below:
$ cat 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)
}
After doing install_github, when I run reverse_complement("AAAAA"), I get the following error:
[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
From the error I can say that it is not finding the path. But is there a way to fix it?
Thanks, Satya
def revcompl():lines. Python is a strong type language requiring syntax rules especially in indentation of functions and loops.inst/python/rev.pyin your directory structure?inst. Even if it works, I would prefer the python directory to be in project's home directory.