Google citations to your webpage

When I decided to add my work stuff to the blog, I knew I needed to present my academic merits in some form. I wanted it to fit the aesthetics of my blog, but be at least partially automatically updated. Keeping my publications and citations on so many social media forums is very annoying, and I didn't want my blog to be taking too much of my time to keep up-to-date when it came to this.

So I did some searching and found this really cool way to use information from google scholar profiles to keep track of my citations and publications also on my blog. Love. it. While google scholar doesn't track all citations, it does so better than for instance Research Gate, and is a good approximation when I don't want to spend time updating it all the time. Most of these steps can already be found on R-bloggers by Bart Rogiers, but I did some tweaking and swapped the use of cron (which is deprecated) with launchd (which is the new OSX periodic runner).

Certain things must be update manually, but as long as I keep my google scholar profile updated, I found a nifty way to periodically run scripts that would update my citations and publications.

You can see the full results of this procedure under "Ego -> The Scientist".



I do this through OSX (mac) and use shell and R scripts in a public dropbox folder which are run daily with launchd (which is native to OSX). If you have experience with these, this should be easy. For my part, the most difficult part was launchd, because I had no experience with it.


Step 1: The Rscript

I have already made a script that works as a function. You can download it here.

It requires two inputs:
USR: your google scholar id
PubURL: a public folder url (I have only tested this with a public dropbox folder, I have the script in the folder which it links to).

The script also requires certain libraries to be installed, make sure you have them:
scholar - necessary to import google scholar information
stringr - necessary to flow publication text over several lines automatically
ggplot2 -  Recommended, makes beautiful plots.
RColorBrewer - Recommended, easy colour palette choices.
knitr - Recommended, cropping the plot (OSX/linux only)

The script will produce the images with default colours in the folder you are working from, you only need to start R, source the file and run the function:

Remember to change your folder path and dropbox public folder link. Save these lines as another script in the same folder as the downloaded script. Call it something intuitive, like "Make_citation_plots.R".

While all the plots are already made, you may want to change some colours or do something more with the data. The plots are ggplots, so you may easily add extra geoms or theme parameters to them. I, for instance, change the colours of my citations chart as you can see at the bottom of the previous script. You may of course also directly change the Rscript function to suit your liking. 

Step 2: The shell script

Ok. I really looked into this alot, and it seems launchd cannot run Rscripts directly, so we need to make a shell script to run the Rscript. Yes, I know, it feels rather redundant, but that is how it is. Also, this needs to be done in bash, I experienced real trouble trying to do it in c-shell (csh; don't ask me why c-shell is the neuroscience norm...). I might just not be getting something, but I made it work with bash, so I didn't really bother looking further.

Make it simple. This is not rocket science. But use complete file paths, do not use variable path names (like $HOME) or the tilde (~). I experienced it failing when I did.

If you don't know where your Rscript command is based, type "which Rscript" in the terminal and copy+paste the resulting path.

Save the bash script, again, call it something meaningful. Like "run_GoogleCite.sh"



Step 3: The launchd script (plist)

So this is where I really started tumbling. Everything else was easy and familiar (I work in R and shell all the time), and this next periodic step was a pain to understand. At least for me.

There is lots of available information about launchd on the net. You can just google it, or look here. I'm not gonna take you through all the steps. I'm just gonna show you what my launchd script looks like, and explain what is does. Hopefully, this will be enough for you to be able to get it going without having to know lots and lots of things.

A launchd script can run with very little information, and is actually easy enough to understand once you have it down and what you want to do is easy (like running a shell script once a day at noon).

First, notice that the "label" is set as a reverse domain name, this is the norm for plists, and you should give it a name so you understand what this plist is doing. The label and filename should be the same, this makes it easy to find and stop if something goes wrong (filename is suffixed with ".plist").

Secondly, again use full paths. No tildes or variable folder names. It does not compute. I wasted about an hour figuring something that simple out.

Third, this script runs on two occasions:
1) when it is initiated (RunAtLoad)
2) at noon (StartCalendarInterval)

I have my plist in "~/Library/LaunchAgents", which runs as the currently logged in user and does not require root. This is safe, and will not mess up any system stuff if you do something wrong. This also means, I have to be logged into this computer at noon for the script to be run. That is generally not a problem, at worst it won't update for a couple of weeks if I'm on vacation.

Below is the plist code I use, which I have saved as "~/Library/LaunchAgents/com.mowinckel.googlecite.plist"



Step 4: Load the plist and debug

This last part is only checking that things work. The steps above should make it easy enough to get going (I know there's a lot of information there, but the steps really aren't that bad). Once all the files are made, in the terminal navigate to "~/Library/LaunchAgents/" and make sure your new plist is in there. Now, this plist will initiate when you reboot, but you can load it manually by typing:

launchctl load com.mowinckel.googlecite.plist

You can check its status by
launchctl list | grep mowinckel

If its status is "0", it is running smoothly. Anything else and it is encountering difficulties. I would then start executing each script manually from terminal to make sure they are functioning properly, and check if the "plist.test.txt" is written to your working folder. If it is not, then the shell script is not being initiated by launchd, and it is the plist which is the problem. Start tweaking and try to solve it by googling, or ask me here, and I'll try to help.

You can also unload the plist to re-load it, if you have done something new and want to test it, by:

launchctl unload com.mowinckel.googlecite.plist





Step 5: Add to webpage

Since this is all done in a public dropbox folder, the links to the creased images are static. Copy+paste the link to the citation image and embed to you webpage with <img>, and the publications html you can add by using <iframe>. Easy and simple.

Good luck on getting it going. I hope my instructions are detailed enough to get properly started without too many hiccoughs. Just let me know if you have any questions, I'll try to answer them best I can.



testing testing

You Might Also Like

0 comments

Let me know what you think!