From ba5f9f2690b198b2e419da0320400c5711f2e30d Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Thu, 19 Nov 2020 13:31:48 +0100 Subject: [PATCH] Added diff --- R/matlab2r.R | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/R/matlab2r.R b/R/matlab2r.R index 8583aff..8656a30 100644 --- a/R/matlab2r.R +++ b/R/matlab2r.R @@ -1,7 +1,7 @@ #' @title Convert Matlab function to R #' @description Performs basic syntax conversion from Matlab to R #' @param filename name of the file -#' @param output can be "asis", "clean" (default), "save" or "append" +#' @param output can be "asis", "clean", "save" or "diff" #' @param improve_formatting if `TRUE` (default), makes minor changes #' to conform to best-practice formatting conventions #' @param change_assignment if `TRUE` (default), uses `<-` as the assignment operator @@ -131,6 +131,18 @@ matlab2r <- function( append = append ) ) + } else if (output == "diff") { + diff_text <- vector(mode="character", length=(2 * length(original) + 1)) + for (i in seq_along(txt)) { + new_i <- (2 * i) + i - 2 + diff_text[new_i] <- paste( + "-----------------------", "line", i, "-----------------------" + ) + diff_text[new_i + 1] <- original[i] + diff_text[new_i + 2] <- txt[i] + } + message("Displaying line number, original content and modified content") + return(cat(diff_text, sep="\n")) } else { stop ("Invalid output argument") }