Friday, 23 August 2013

Load image from website

Load image from website

I am trying to add some chemical structure images to some plots I have
created. I am using the ACToR database to access the chemical structures.
For example:
http://actor.epa.gov/actor/image?format=png%3Aw250%2Ch250&casrn=80-05-7
The nice thing about this site is you can change the size and the chemical
within the url, so I can automate grabbing the images. My hope was to
store an object containing CAS numbers, then iterate through the CAS
numbers to make the plots.
For example:
library(png)
casnums <- ("80-05-7","77-40-7","1478-61-1")
image.list <- list()
for(cas in casnums){
image.list[[cas]] <-
readPNG(paste0("http://actor.epa.gov/actor/image?format=png%3Aw1000%2Ch1000&casrn=",cas))
}
I have tried using readPNG from the png package, and tried to use the
rgdal package as well. Unfortunately, as far as I can tell, ACToR will
only generate the images in a png or jpeg format - so I cannot use the
grImport package for reading vector images.
I am really hoping to find a solution where I do not have to manually
download each image - there are a lot of them. I would be open to a
solution where R goes and dowloads the images to a folder, then I could
use something like the png package, or the rgdal package to load the image
and plot them.

No comments:

Post a Comment