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 (i in 1:npops) {
|
||||||
for (j in 1:nloci) {
|
for (j in 1:nloci) {
|
||||||
i_rivit <- rows(i, 1):rows(i, 2)
|
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)
|
sumcounts(i, j) <- length(havainnotLokuksessa)
|
||||||
for (k in 1:noalle[j]) {
|
for (k in 1:noalle[j]) {
|
||||||
alleleCode <- k
|
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
|
counts(k, j, i) <- N_ijk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
R/matlab2r.R
11
R/matlab2r.R
|
|
@ -1,8 +1,8 @@
|
||||||
#' @title Convert Matlab function to R
|
#' @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 filename name of the file
|
||||||
#' @param saveOutput if `TRUE`, `filename` is overwritten. Defaults to `FALSE`
|
#' @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
|
#' @author Waldir Leoncio
|
||||||
#' @export
|
#' @export
|
||||||
matlab2r <- function(filename, saveOutput = FALSE) {
|
matlab2r <- function(filename, saveOutput = FALSE) {
|
||||||
|
|
@ -11,9 +11,16 @@ matlab2r <- function(filename, saveOutput = FALSE) {
|
||||||
# Reading file into R
|
# Reading file into R
|
||||||
txt <- readLines(filename)
|
txt <- readLines(filename)
|
||||||
# Replacing text
|
# Replacing text
|
||||||
|
txt <- gsub(
|
||||||
|
pattern = "function (.+)\\s*=\\s*(.+)\\((.+)\\)",
|
||||||
|
replacement = "\\2 <- function(\\3) { return(\\1)",
|
||||||
|
x = txt
|
||||||
|
)
|
||||||
txt <- gsub(";", "", txt)
|
txt <- gsub(";", "", txt)
|
||||||
txt <- gsub("for (.+)=(.+)", "for (\\1 in \\2) {", txt)
|
txt <- gsub("for (.+)=(.+)", "for (\\1 in \\2) {", txt)
|
||||||
txt <- gsub("end", "}", txt)
|
txt <- gsub("end", "}", txt)
|
||||||
|
# TODO: replace forms like (:,:) with [, ]
|
||||||
|
# TODO: reformat if statements
|
||||||
# Returning converted code
|
# Returning converted code
|
||||||
if (!saveOutput) {
|
if (!saveOutput) {
|
||||||
return(cat(txt, sep="\n"))
|
return(cat(txt, sep="\n"))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue