gscholar.R
.# load packages
if (!require("pacman")) install.packages("pacman"); library(pacman) # conditional installation of the packages below
p_load(scholar,ggplot2,scales)
#
cit <- get_citation_history('3FHDoL0AAAAJ&hl')
p = ggplot(cit,aes(x=year,y=cites))+
geom_bar(stat='identity')+
theme_bw()+
xlab('Year')+
ylab('Citations') +
scale_y_continuous(labels = number_format(accuracy = 1), breaks = round(seq(min(cit$cites), max(cit$cites), by = 1),1)) +
scale_x_continuous(breaks = round(seq(min(cit$year), max(cit$year), by = 1),1)) +
annotate('text',label=format(Sys.time(), "%Y-%m-%d"),x=-Inf,y=Inf,vjust=1.5,hjust=-0.05,size=3,colour='gray') +
theme_classic() +
theme(#axis.text.y = element_text(size=14),
#axis.text.x = element_text(size=14),
#axis.title.y = element_text(size=14),
#axis.title.x = element_text(size=14),
#panel.background = element_blank(),
#panel.grid.major = element_blank(),
#panel.grid.minor = element_blank(),
#axis.line = element_line(colour = "black"),
panel.border = element_rect(colour = "black", fill=NA, size=1)) +
ggtitle("Google Scholar Citations (updated daily)")
png("/Users/hectorbahamonde/Dropbox/scholar_citations.png",width=2200,height=1000,res=250)
print(p)
dev.off()
3FHDoL0AAAAJ&hl
with your Google Scholar user number. You can find yours in your Google Scholar profile URL. In my case that is,https://scholar.google.com/citations?user=3FHDoL0AAAAJ&hl=en
…that is, your user name is whatever is right after "user="
.
scholar_citations.png
to your DropBox folder (make sure your DropBox folder is “/Users/HERE/…”).Go to DropBox, and get a shareable link of the plot scholar_citations.png
(like this).
Now the crontab part. Open terminal and type the following in this exact same order:
env EDITOR=nano crontab -e
Hit enter
.MAILTO=""
Hit enter
This task suppresses alerts sent to you every time the task is executed.0 9 * * * /usr/local/bin/Rscript -e 'source("/Users/hectorbahamonde/hbahamonde.github.io/gscholar.R")'
Hit enter
This task is the R script task itself. This is ONE line, so make sure you copy and paste this line into terminal as one line.CTRL
+o
. This saves the crontab task. To be sure, this is the “o” character, not a zero (0).enter
. This one just accepts the task name.CTRL
+x
. And this one closes down crontab. Mac might ask you if you want to let Terminal to modify your files. Accept that.
OK; that was the crontab part.
All this process ensures that your machine will automatically execute the R script gscholar.R
every day at 9AM (make sure your computer is turned on by that time otherwise, crontab won’t be able to execute this task). If you need more specific times, see this link and replace the 0 9 * * *
part with another time configuration.
gscholar.R
is correct in your case. That is, in your case it should be something like this: 'source("/Users/YOUR_USER/YOUR_FOLDER_WHERE_YOU_KEEP_THE_SCRIPT_DESCRIBED_IN_STEP_1/gscholar.R")'
.scholar_citations.png
plot (as described in step 2), insert the following HTML code to embed your daily-generated Google Scholar citations plot into your website. The DropBox link should go after src=
. Notice that you have to replace whatever is after the ?
symbol to raw=1
.<img src="https://www.dropbox.com/s/hlroz3qjeyrwmta/scholar_citations.png?raw=1" alt="gscholar" style="width:800px;height:600;;border:0;">
I borrowed this from Ole Michelsen. I also got help from here. And from here. This one was important because my terminal window was very narrow, and I think it was indenting the crontab task described in 3.b in two lines, causing the task not to save. Thanks guys!
]]>curl -L http://xrl.us/installperlosx | bash
texmf.cnf
is. In terminal, kpsewhich texmf.cnf
.\newcommand\wordcount{
\immediate\write18{texcount -sub=section \jobname.tex | grep "Section" | sed -e 's/+.*//' | sed -n \thesection p > 'count.txt'}
(\input{count.txt}words)}
\makeatletter\@@input|"echo `texcount -1 myfile.tex`| cut -c1-4"\makeatother
Thanks to Lelkes for making these scripts available.
Here is another one that does not need any extra things. Just copy/paste the code below at the end of your .rnw document.
\clearpage
<<wordcount, echo=FALSE, cache=FALSE>>=
library(knitr)
comma <- function (x, ...) {
format(x, ..., big.mark = ",", scientific = FALSE, trim = TRUE)
}
# To dynamically extract name of the current file, use code below
nameoffile <- current_input() # get name of file
nof2 <- strsplit(nameoffile,"\\.")[[1]][1] # extract name, drop extension
noftex <- paste(nof2, ".tex", sep="") # add .tex extension
systemcall <- paste("system('texcount -inc -incbib -total -sum ", noftex, "', intern=TRUE)", sep="") # paste together texcount system command
texcount.out <- eval(parse(text=systemcall)) # run texcount on current last compiled .tex file
sum.row <- grep("Sum count", texcount.out, value=TRUE) # extract row
pattern <- "(\\d)+" # regex pattern for digits
count <- regmatches(sum.row, regexpr(pattern, sum.row) )
# extract digits
count <- comma(as.numeric(count)) # add comma
@
\begin{center}
\vspace*{\stretch{1}}
\dotfill
\dotfill {\huge {\bf Word count}: \Sexpr{count}} \dotfill
\dotfill
\vspace*{\stretch{1}}
\end{center}
\clearpage
I borrowed this from Omar Wasow. Thanks!
]]>The main idea is to outsource your R
code into LaTeX
automatically. For example, this way you do not have to copy and paste standard errors, or figures. It will be automatically generated in your PDF file after compiling the .rnw
.
Text processor and necessary dependencies: First you will need a software to handle code and syntax highlighting. I use Sublime Text 3. Have Sublime Text 3 installed.
shift+cmd+p
, then Install Packages, and install:
install.packages(c("knitr", "formatR", "pacman"), repos = "http://cran.rstudio.com")
{"knitr": true, /* activates knitr function */
"quick_build": [ /* activates latexing capabilities? Not sure. */
{
"name": "Primary Quick Build: latexmk",
"primary": true,
"cmds": ["latexmk"]
}
],
"keep_focus": true, /* activates skim sync and pop up function */
"keep_focus_delay": 0.1, /* reduces skim sync time */
"pdf_viewer_osx": { /* makes sure skim is the default app. User should make sure that the NAME OF the app is correct too (it might change with some updates) */
"skim": [
"/Applications/Skim.app"
],
"preview": [
"/Applications/Preview.app"
]
}
}
1) In your .rnw
file, just generate an environment that includes a tag that’s shared with the R
file, like so:
<<chunk:example, echo = FALSE, cache = FALSE>>=
@
In this example, the tag is chunk:example
. Also, editors and (most) readers are not interested in your coding. That’s fine. The important thing is to make your code available to the audience that needs it. You can hide it by calling the echo = FALSE
function in the preamble, i.e. within the <<>>=
symbols. Also, the cache = FALSE
makes sure that your computer does not store whatever you command it to do (graphs, data, etc.). I think it’s important to set it in FALSE
so fresh plots, tables, and datasets are generated every time. This way you are absolutely sure that whatever is in your PDF reflects the latest compile.
2) In your R script, have another environment where you actually host the code, like so:
## ---- chunk:example
set.seed(602)
library(MASS) # to generate multi-var distribution
e <- as.numeric(mvrnorm(n = 100, mu = 0, Sigma = 1))
plot(e)
##
Thus, every time you compile your .rnw
file, R
will execute the chunk:example
chunk, and insert whatever is there (a table, a plot, a number, etc.).
Some people prefer having the R
code within the .rnw
file. My R
code is always very long, which distracts me from writing. Thus, I prefer to have my R
code separated from the .rnw
file. It’s easily shareable, and more convenient.
Download Skim (pdf viewer).
.md
files before uploading them to my GitHub account. While in Sublime Text writing your .md
file, use Control + Shift + M
to preview.Command + Alt + N
.Control + Shift + C
.Building on this blog post, I changed the default visuals for the following ones:
Sublime Text > Preferences > Settings - User
, then paste,{
"bold_folder_labels": true,
"caret_style": "phase",
"fade_fold_buttons": false,
"font_face": "Monaco",
"font_size": 17,
"highlight_line": true,
"highlight_modified_tabs": true,
"ignored_packages":
[
"Vintage"
],
"line_padding_bottom": 2,
"line_padding_top": 2,
"word_wrap": true
}