Minor improvements to translator function
This commit is contained in:
parent
4d2a00403b
commit
97af90d05d
2 changed files with 24 additions and 1 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#' @param saveOutput if `TRUE`, `filename` is overwritten. Defaults to `FALSE`
|
||||
#' @return text converted to R, printed to screen or replacing input file
|
||||
#' @author Waldir Leoncio
|
||||
#' @importFrom utils write.table
|
||||
#' @export
|
||||
matlab2r <- function(filename, saveOutput = FALSE) {
|
||||
# Verification
|
||||
|
|
@ -21,7 +22,7 @@ matlab2r <- function(filename, saveOutput = FALSE) {
|
|||
txt <- gsub("for (.+)=(.+)", "for (\\1 in \\2) {", txt)
|
||||
txt <- gsub("end", "}", txt)
|
||||
txt <- gsub("(.),(\\S)", "\\1, \\2", txt)
|
||||
# TODO: replace forms like (:,:) with [, ]
|
||||
# TODO: replace forms like (:,:) with [, ] if they come before <-
|
||||
# TODO: add argument to skip some of these rules
|
||||
txt <- gsub("if (.+)", "if (\\1) {", txt) # FIXME: paste comments after {
|
||||
txt <- gsub("else$", "} else {", txt)
|
||||
|
|
|
|||
22
man/matlab2r.Rd
Normal file
22
man/matlab2r.Rd
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/matlab2r.R
|
||||
\name{matlab2r}
|
||||
\alias{matlab2r}
|
||||
\title{Convert Matlab function to R}
|
||||
\usage{
|
||||
matlab2r(filename, saveOutput = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{filename}{name of the file}
|
||||
|
||||
\item{saveOutput}{if `TRUE`, `filename` is overwritten. Defaults to `FALSE`}
|
||||
}
|
||||
\value{
|
||||
text converted to R, printed to screen or replacing input file
|
||||
}
|
||||
\description{
|
||||
Performs basic syntax conversion from Matlab to R
|
||||
}
|
||||
\author{
|
||||
Waldir Leoncio
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue