Skip to content

Instantly share code, notes, and snippets.

@lmmx
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmmx/9bdec10b4307d640fade to your computer and use it in GitHub Desktop.
Save lmmx/9bdec10b4307d640fade to your computer and use it in GitHub Desktop.
Example JSON for replicating SIGPIPE error when piping from an Rscript - http://stackoverflow.com/q/28915838/2668831
{"id":"abcdefg","title":"Example note 1","content":"Lorem ipsum.","taskAll":0,"taskCompleted":0,"created":0000000000000,"updated":1111111111111,"notebookId":0,"tags":[],"isFavorite":0,"trash":0,"synchronized":0,"images":[],"redirect":true}
{"id":"hijklmn","title":"Example note 2","content":"Dolor sit amet.","taskAll":0,"taskCompleted":0,"created":0000000000000,"updated":1111111111111,"notebookId":0,"tags":[],"isFavorite":0,"trash":0,"synchronized":0,"images":[],"redirect":true}
#!/usr/bin/env Rscript
#library('RJSONIO')
note.list <- c('abcdefg.json',
'hijklmn.json')
for (laverna.note in note.list) {
# note.file <- path.expand(file.path('~/Dropbox/Apps/Laverna/notes',laverna.note))
# For the purpose of this example run the script in the same directory as the JSON files
note.file <- path.expand(file.path(getwd(),laverna.note))
file.conn <- file(note.file)
suppressWarnings(
# cat(paste0(fromJSON(file.conn)$content),'\n')
cat(paste0(substr(readLines(file.conn), 2, 15)),'\n')
)
# close(file.conn)
}
# Rscript myscript.R
# ==>
# "id":"abcdefg"
# "id":"hijklmn"
# Rscript myscript.R | head -2
# ==>
# "id":"abcdefg"
# "id":"hijklmn"
# Error: ignoring SIGPIPE signal
# Execution halted
# Rscript myscript.R | head -1
# ==>
# "id":"abcdefg"
# Error: ignoring SIGPIPE signal
# Execution halted
# closing all connections at the end with
# closeAllConnections()
# does not affect the race condition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment