Skip to content

Instantly share code, notes, and snippets.

@Dulani
Dulani / Desc_JSON_to_df.md
Created March 17, 2017 18:17 — forked from gluc/Desc_JSON_to_df.md
Convert a complex JSON to an R data.frame

This gist shows how to convert a nested JSON file to an R data.frame. To do this, it uses jsonlite and data.tree.

The gist contains two examples: one is a bit simpler, the second one a bit more advanced.

Example 1

In the first example, we download all the repos from Hadley Wickham's Github account from https://api.github.com/users/hadley/repos . This JSON contains a nested owner object. The code shows how to convert that in a flat data.frame in three statements:

  1. line 5: download
  2. line 8: convert to data.tree
@Dulani
Dulani / webdav.R
Created November 16, 2016 20:18
R helper functions for performing WebDAV tasks
library(curl)
library(XML)
listFiles <- function(username, password, relPath = "/", dav = "https://dav.box.com/dav") {
uri <- URLencode(paste(dav, relPath, sep=""))
# fetch directory listing via curl and parse XML response
h <- new_handle()
handle_setopt(h, customrequest = "PROPFIND")
handle_setopt(h, username = username)
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite