As requested by @chrisfilo , I'm doing this as an issue as I can't contribute to the wiki. Here's some markdown regarding writing and reading .json and .tsv files from R.
R
There are several packages for reading and writing JSON files from R. In this example we will be using jsonlite. Remember to install and call a package before using it.
https://github.com/jeroen/jsonlite
Installing required package
install.packages('jsonlite')
Reading a .json
file
library(jsonlite)
data = fromJSON('myfile.json', pretty=TRUE)
Writing a .json
file
library(jsonlite)
data = {'field1': 'value1', 'field2': 3, 'field3': 'field3'}
writeLines(toJSON(data, pretty=TRUE), file="myData.json")
R
Reading and writing tab separated files comes natively in R, no need for extra packages.
Reading a .tsv
file
In this example, we assume the .tsv includes column names (headers), and explicitly set column separator (delimitor) to tab ('\t')
data = read.table('myFile.tsv', header=TRUE, sep='\t')
Writing a .tsv
file
When writing files, colum and row names are always saved, we remove row names, and quotes from the outpur explicitly by setting them to FALSE.
data = cbind.data.frame(
participant_id = c('sub-01', 'sub-02'),
age = c(20,30),
sex = c('m','f'))
write.table(data, file='myData.tsv',sep='\t',
row.names = FALSE, quote = FALSE)