Fixed syntax
This commit is contained in:
parent
0b6a899de8
commit
228b4d808a
2 changed files with 12 additions and 5 deletions
|
|
@ -6,11 +6,11 @@ initialPopCounts <- function(data, npops, rows, noalle, adjprior) {
|
|||
for (i in 1:npops) {
|
||||
for (j in 1:nloci) {
|
||||
i_rivit <- rows(i, 1):rows(i, 2)
|
||||
havainnotLokuksessa <- find(data(i_rivit, j) >= 0)
|
||||
havainnotLokuksessa <- find(data[i_rivit, j] >= 0)
|
||||
sumcounts(i, j) <- length(havainnotLokuksessa)
|
||||
for (k in 1:noalle[j]) {
|
||||
alleleCode <- k
|
||||
N_ijk <- length(find(data(i_rivit, j) == alleleCode))
|
||||
N_ijk <- length(find(data[i_rivit, j] == alleleCode))
|
||||
counts(k, j, i) <- N_ijk
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
R/matlab2r.R
13
R/matlab2r.R
|
|
@ -1,8 +1,8 @@
|
|||
#' @title Convert Matlab function to R
|
||||
#' @description Performs basic syntax conversion
|
||||
#' @description Performs basic syntax conversion from Matlab to R
|
||||
#' @param filename name of the file
|
||||
#' @param saveOutput if `TRUE`, `filename` is overwritten. Defaults to `FALSE`
|
||||
#' @return text converted to R
|
||||
#' @return text converted to R, printed to screen or replacing input file
|
||||
#' @author Waldir Leoncio
|
||||
#' @export
|
||||
matlab2r <- function(filename, saveOutput = FALSE) {
|
||||
|
|
@ -11,9 +11,16 @@ matlab2r <- function(filename, saveOutput = FALSE) {
|
|||
# Reading file into R
|
||||
txt <- readLines(filename)
|
||||
# Replacing text
|
||||
txt <- gsub(
|
||||
pattern = "function (.+)\\s*=\\s*(.+)\\((.+)\\)",
|
||||
replacement = "\\2 <- function(\\3) { return(\\1)",
|
||||
x = txt
|
||||
)
|
||||
txt <- gsub(";", "", txt)
|
||||
txt <- gsub("for (.+)=(.+)", "for (\\1 in \\2) {", txt)
|
||||
txt <- gsub("end", "}", txt)
|
||||
# TODO: replace forms like (:,:) with [, ]
|
||||
# TODO: reformat if statements
|
||||
# Returning converted code
|
||||
if (!saveOutput) {
|
||||
return(cat(txt, sep="\n"))
|
||||
|
|
@ -28,4 +35,4 @@ matlab2r <- function(filename, saveOutput = FALSE) {
|
|||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue