Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using your package "flickRgeotag" - update needed? #11

Open
maevemaria opened this issue Jul 8, 2020 · 9 comments
Open

Error when using your package "flickRgeotag" - update needed? #11

maevemaria opened this issue Jul 8, 2020 · 9 comments

Comments

@maevemaria
Copy link

Dear Dr Daigle,

I came across your package "flickRgeotag" which is exactly what I would need for my analysis using flickr.photo.search

However, when I try to use it I always end up with the same error, even when making use of your sample code flickr.photos.search(api_key, bbox=NULL, extras=c("geo","tags","date_taken","url_m"), output="metadata",.allpages=FALSE, .usecache=TRUE) found here: https://rdrr.io/github/remi-daigle/flickRgeotag/src/R/flickrphotossearch.R

The error I'm getting is:

Error in xml2::url_escape(searchparams[[item]]) : STRING_ELT() can only be applied to a 'character vector', not a 'double'

I would like to thank you in advance for your time on this matter!

Kind regards,
Maeve Smyth

@remi-daigle
Copy link
Owner

remi-daigle commented Jul 8, 2020

Hi Maeve,
If you install from github with the latest version now, I believe the error will now be fixed. e.g.:
devtools::install_github("https://github.com/remi-daigle/flickRgeotag")
Please let me know either way!
Thanks,
Remi

@maevemaria
Copy link
Author

Dear Remi,

Many thanks, I will try this now.

Best wishes,
Maeve

@maevemaria
Copy link
Author

Hi Remi,

I am still getting the same error unfortunately. Could this have to do with the fact that I cannot install the package "Rtools"? When I try to install that one I get an error message: package ‘Rtools’ is not available (for R version 4.0.1)

Best,
Maeve

@remi-daigle remi-daigle reopened this Jul 8, 2020
@remi-daigle
Copy link
Owner

I think you are likely still using the 'old' version of the package? To confirm can you do:

packageVersion("flickRgeotag")

Assuming that doesn't give you '0.1.1', then that means you are still using an old version (i.e. failed to install the new version).

Rtools is not a package, but rather a tool used to build packages. You need it to install most packages you'll find on GitHub (including flickRgeotag), you can find it here for Windows: https://cran.r-project.org/bin/windows/Rtools/

Once you have installed Rtools, then you need to install devtools, then you can try to install flickRgeotag.

@maevemaria
Copy link
Author

Hi Remi,

Thank you! After some trying around it appears to work now. The only thing is I cannot get a list of more than 250 photos. If I try the command ".allpages = TRUE" I get the same error as above. I assume the amount of output is simply too much for R. Do you happen to know a workaround here?

Alternatively, I have tried setting the number of pictures returned by adjusting the arguments "per_page" and "page", but this doesn't appear to change anything. Ideally, I would want all pictures though (close to 280,000 in total).

@remi-daigle
Copy link
Owner

It sounds like it's a problem (that I didn't fix yet) with the package... I'll investigate, more from me soon

@remi-daigle
Copy link
Owner

OK, it should be fixed now!

I should note that for 280,000 photos, you will encounter problems! I've noticed that if you ask the API for more than ~1500 photos, you do not get everything you asked for (likely flickr trying to protect its servers?). You need to narrow your search parameters (tags, dates, bbox) if you want to get ALL the data, but you can make many smaller queries.

We've created splitbbox() specifically for this purpose. It will create many sub-bboxes of an appropriate size that you can use to repeatedly query flickr and then you can bind the results together afterwards. e.g.:

library(prettymapr)
library(flickRgeotag)
bb <- searchbbox("halifax, NS")
sub_bbox <- splitbbox(bbox=bb, text="water", min_taken_date="2016-01-01",.allpages=TRUE)

@maevemaria
Copy link
Author

maevemaria commented Jul 15, 2020

Hi Remi,

Thank you, it worked now when I divided a year's worth of photos into 3 parts and then used splitbbox. This might be of interest to you, when I tried to apply splitbbox to the photos of a whole year it started off with many splitting iterations but in the end returned the following error:

cannot open URL 'https://api.flickr.com/services/rest/?.......': HTTP status was '500 Internal Server Error'Error in splitbbox(api_key, sub_bbox[i], extras, .allpages, .usecache, :
Error occured in call to flickr.photos.search: Unable to connect to URL (code: -1)

But I assume this is just Flickr not accepting such a large extraction.

One more question, I am not sure how to use the output generated by splitbbox( ) as opposed to flickr.photos.search( ). The list generated appears to only contain coordinates, is there some way to "unpack" the information again? Or do you have some existing documentation/ user guide info typed up on this?

Many thanks!

@fjmurguzur
Copy link

fjmurguzur commented Jan 12, 2021

@maevemaria , I have had issues with the .allpages=TRUE command retrieving an error, and I have managed to pin down the error to a tiny issue with the page number format in the restquery function. I guess that the package xml2 has been updated, and that has led to some issues with the flickRgeotag package: xml2 interprets the page numbers as double, while it should be a character (or probably numeric, didn't try that). If you use .allpages=FALSE, yo get the first 100 results; if you use .allpages=FALSE, page=as.character(10), you will get the 10th page (note the as.character for the page number).

@remi-daigle , This seems like a minor issue coming from the xml2 package. My workaround right now is to make a frankestein function where I download the "raw" object as an object to my environment, and then extract from there the number of pages, which i subsequently include in a loop where I call the getphotos with as.character() in the page number. That works fine (for now). Drop me a line if I can help you :)

ETA: This is the script I have used, and it works. It is not the most efficient, but it gets the job done. For

flickr.photo.location<-list() #Create an empty list to store all the photo information
for(j in 1:length(owners)){ #the object "owner" is a vector with the names of the owners I am looking for

queryparams<-list()
queryparams$method = "flickr.people.getPhotos"
queryparams$api_key <- api_key
queryparams$user_id <- as.character(owners[j])
queryparams$extras <- "geo,tags,date_taken,url_m"
raw <- do.call(flickr.restquery, queryparams) #This gives me the number of pages for a given owner
temp<-list() #Create an empty list to store the extracted data

for(w in 1:raw$photos$pages){ #loop through the pages

temp[[w]]<-flickr.people.getPhotos(api_key = api_key,user_id=as.character(owners[j]),page=as.character(w),extras="geo,tags,date_taken,url_m",.allpages=FALSE)[,c("id","owner","latitude","longitude","url_m")] #All I want here is the photo ID (to get the unique values), coordinates and the link. this makes the dataset smaller and easier to handle
}
flickr.photo.location[[j]]<-do.call(rbind.data.frame,temp) #Collapse the "temp" list into the main list

}

flickr.dataset<-do.call(rbind.data.frame,flickr.photo.location) #Here I collapse all the information I wanted to store

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants