Adding md2csv and tab2md functions.
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
md2csv<-function(text, rm_blank=T){
|
||||||
|
text<-strsplit(text, "\n")[[1]]
|
||||||
|
text<-gsub("^[ |]*|[|][ ]*$","",text)
|
||||||
|
if(rm_blank){text<-gsub(" ","",text)}
|
||||||
|
text<-gsub("[|]",",",text)
|
||||||
|
return(cat(text,sep = "\n"))
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
tab2md<-function(table){
|
||||||
|
samples_csv<-table
|
||||||
|
table<-apply(table, 1, paste, collapse="|")
|
||||||
|
table<-gsub("^","|",table)
|
||||||
|
table<-gsub("$","|",table)
|
||||||
|
table<-c(paste0("|",paste(colnames(samples_csv), collapse="|"),"|"),
|
||||||
|
paste0("|",paste(rep("---",ncol(samples_csv)), collapse="|"),"|"),
|
||||||
|
table)
|
||||||
|
cat(table, sep="\n")
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
\name{md2csv}
|
||||||
|
\alias{md2csv}
|
||||||
|
\title{md2csv}
|
||||||
|
\usage{
|
||||||
|
md2csv(text, rm_blank =T)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{text}{An md text that you want to convert to csv. Note that you must eliminate the line that separates title from the rest.}
|
||||||
|
\item{text}{Bolean to specify if you want to remove spaces or not.}
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
This function converts an Markdown (md) table into csv format.
|
||||||
|
}
|
||||||
|
\examples{
|
||||||
|
text<-"|Letter|Number|
|
||||||
|
|A| 1|
|
||||||
|
|B| 2|
|
||||||
|
|C| 3|
|
||||||
|
|D| 4|
|
||||||
|
|E| 5|
|
||||||
|
|F| 6|
|
||||||
|
|G| 7|
|
||||||
|
|H| 8|
|
||||||
|
|I| 9|
|
||||||
|
|J|10|"
|
||||||
|
md2csv(text)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
\name{tab2md}
|
||||||
|
\alias{tab2md}
|
||||||
|
\title{tab2md}
|
||||||
|
\usage{
|
||||||
|
tab2md(text)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{text}{A data.frame that you want to convert to Markdown.}
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
This function converts a data.frame into Markdown (md) format.
|
||||||
|
}
|
||||||
|
\examples{
|
||||||
|
table<-data.frame("Letter"=LETTERS[1:10], "Number"=1:10)
|
||||||
|
tab2md(table)
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user