Skip to content

Instantly share code, notes, and snippets.

@d0choa
Created March 11, 2016 11:25
Show Gist options
  • Save d0choa/af179797616c2d227620 to your computer and use it in GitHub Desktop.
Save d0choa/af179797616c2d227620 to your computer and use it in GitHub Desktop.
This R script displays the number of manuscripts in each journal stored in the Mekentosj's Papers database during the last n years
## getJournalsFreq.R
## author: David Ochoa <dogcaesar@gmail.com>
## The script displays the number of manuscripts in each journal stored in the Mekentosj's Papers database
topN <- 20 #Top journals to display
lastyears <- 5 #Last n years
journalsquery <- "osascript -ss -e 'tell application \"Papers\" to get bundle name of publication items'"
yearsquery <- "osascript -e 'tell application \"Papers\" to get publication year of publication items'"
journals <- paste(system(journalsquery, intern=TRUE),collapse="")
journals <- gsub("\\{","",journals)
journals <- gsub("\\}","",journals)
journals <- unlist(strsplit(journals,"\", \""))
journals <- gsub("\\\"","",journals)
years <- unlist(strsplit(paste(system(yearsquery, intern=TRUE),collapse=""), ", "))
years[years == "missing value"] <- NA
df <- data.frame(journals=journals,years=as.numeric(years))
thisyear <- as.numeric(unlist(strsplit(as.character(Sys.time()),"-"))[1])
bundle_freq <- table(as.character(df[df$year > (thisyear - lastyears),"journals"]))
# Plotting
topJournals <- tail(sort(bundle_freq), n=topN)
colors <- colorRampPalette(c("#DEEBF7", "#084594"))
pdf(file="journalFreq.pdf")
par(las=2,
mar=c(5,12,4,2))
barplot(topJournals,
main=paste("# of Manuscripts in my Papers Library (last",lastyears,"years)"),
horiz=TRUE,
border=FALSE,
xlab="Manuscripts",
col=colors(topN))
dev.off()
@d0choa
Copy link
Author

d0choa commented Mar 11, 2016

Description

This R script displays the number of manuscripts in each journal stored in the Mekentosj's Papers database during the last n years. It does not require any additional files.

Requirements

  • R
  • Papers (of course)

Usage

Rscript getJournalsFreq.R

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment