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:
Here is an approach that worked for me for a single image (it could be wrapped in a function to be used in the loop):
con <- url("http://actor.epa.gov/actor/image?format=png%3Aw1000%2Ch1000&casrn=1478-61-1",
open='rb')
rawpng <- readBin(con, what='raw', n=50000)
close(con)
png1 <- readPNG(rawpng)
I tested it using:
plot(1:10, type='n')
rasterImage( as.raster(png1), 3,3,8,8 )
It took some guesswork to get the 50000 and that may be different for other files (actually I should have used 48849, but then it really would be likely to change between files).