From f79c4eeb5c0b8062d7ab8387e656e789137539a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Todor=20Kondi=C4=87?= <todor.kondic@uni.lu>
Date: Wed, 29 Apr 2020 07:36:16 +0200
Subject: [PATCH] R/base.R: Switch to data.table and add a nice print function

* R/base.R (tab2file,file2tab): Return and write data.table objects.

(print_table): New function. Prints a data frame, or a table nicely.
---
 R/base.R | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/R/base.R b/R/base.R
index 9e3b28f..085abf3 100644
--- a/R/base.R
+++ b/R/base.R
@@ -12,16 +12,17 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 
+
+##' @import data.table
+## Redirections
+the_ifelse <- data.table::fifelse
+
 tab2file<-function(tab,file,...) {
-    write.csv(x=tab,file=file,row.names=F,...)
+    data.table::fwrite(x=tab,file=file,...)
 }
 
-file2tab<-function(file,stringsAsFactors=F,comment.char='',sep=',',...) {
-    read.csv(file=file,
-             header=T,
-             stringsAsFactors=stringsAsFactors,
-             comment.char=comment.char,
-             na.strings=c("","NA"),...)
+file2tab<-function(file,na.strings=c("","NA"),...) {
+    data.table::fread(file=file,na.strings = na.strings, ...)
 }
 
 isThingFile<-function(fn) {
@@ -35,3 +36,8 @@ split_path <- function(path) {
   if (dirname(path) %in% c(".", path)) return(basename(path))
   return(c(basename(path), split_path(dirname(path))))
 }
+
+
+print_table <- function (df) {
+    paste(apply(df,1,function (row) paste(row,collapse=',')),collapse = "\n")
+}
-- 
GitLab