I'm trying to assign an R output
my_r_output <- data.frame( Abundances=c(50.00, 30.00, 20.00), Microbes=c("Microbe1", "Microbe2", "Microbe3"), Test=c(1,1,1))
to a javascript variable in my RMarkdown document to obtain something like this when it is converted into a .md document:
var abundances = 'Abundances Microbes Test
50.00 Microbe1 1
30.00 Microbe2 1
20.00 Microbe3 1
'
My R output is a dataframe and the Javascript variable has to be a TSV formatted string.
I tried the following command:
var abundances = '`r write.table( my_r_output, file = "", sep = "\t" )`'
file = ""
to write to stdoutsep = "\t"
to obtain TSV formatted string
But I obtain the following result when the .Rmd is converted into a .md document:
var abundances = '
UPDATE1:
Based on Martin Schmelzer reply I tried the following command in my .Rmd document:
var abundances = '`r paste(capture.output(write.table( my_r_output, file = "", sep = "\t" )), "\n", sep="") `'
And I obtain the follwing results in my .md document:
var abundances = 'Abundances Microbes Test
, 50.00 Microbe1 1
, 30.00 Microbe2 1
, 20.00 Microbe3 1
'
But it added commas at the beginning of each row.