Comments (7)
Too few citations? ;-)
Sort of. The code relies on finding years and bars indicating number of citations separately. You have one year (2009) in your chart without citations. There is no 0 height bar for 2009. Looking at the code I don't see an easy fix without reworking the code e.g. to look at the x axis position of the bars and figure out where there are gaps.
from scholar.
Actually there seems some information in the style tag. This fixes for me (see if(length(years)>length(vals)){
):
get_citation_history <- function(id) {
## Ensure only one ID
id <- tidy_id(id)
## Read the page and parse the key data
url_template <- "http://scholar.google.com/citations?hl=en&user=%s&pagesize=100&view_op=list_works"
url <- sprintf(url_template, id)
## A better way would actually be to read out the plot of citations
page <- GET(url, handle=getOption("scholar_handle")) %>% read_html()
years <- page %>% html_nodes(xpath="//*/span[@class='gsc_g_t']") %>%
html_text() %>% as.numeric()
vals <- page %>% html_nodes(xpath="//*/span[@class='gsc_g_al']") %>%
html_text() %>% as.numeric()
if(length(years)>length(vals)){
# Some years don't have citations.
# We need to match the citation counts and years
# <a href="javascript:void(0)" class="gsc_g_a" style="left:8px;height:5px;z-index:9">\n <span class="gsc_g_al">2</span>\n</a>
style_tags=page %>% html_nodes(css = '.gsc_g_a') %>%
html_attr('style')
# these z indices seem to be the indices starting with the last year
zindices=as.integer(stringr::str_match(style_tags, 'z-index:([0-9]+)')[,2])
# empty vector of 0s
allvals=integer(length=length(years))
# fill in
allvals[zindices]=rev(vals)
# and then reverse
vals=rev(allvals)
}
df <- data.frame(year=years, cites=vals)
return(df)
}
from scholar.
Yes that did the trick! Thanks 👍
from scholar.
Hi, unfortunately I spoke too soon. The fix makes the function not crash, but it doesn't get the years and citations lined up properly. The problem is these two lines:
# fill in
allvals[zindices]=rev(vals)
# and then reverse
vals=rev(allvals)
When you do a reverse, the missing value then lines up with the second most recent year instead of the second oldest year. Here is some code that works (though you might have a more efficient way of doing it):
zindices=as.integer(stringr::str_match(style_tags, 'z-index:([0-9]+)')[,2])
allvals=integer(length=length(years))
i = 1
j = 1
prev = length(years)+1
for(z in zindices) {
if((z+1) != prev) {
i = i+1
}
allvals[i] = vals[j]
i = i+1
j = j+1
prev = z
}
Basically what I'm doing is checking if the previous zindex
has a break in continuity. If it does then there were no citations for this year and we should just use the 0 that was already placed in allvals
.
from scholar.
Sorry you're right there was one rev too many. It should have been:
# fill in
allvals[zindices]=vals
# and then reverse
vals=rev(allvals)
from scholar.
Try devtools::install_github("jefferis/scholar@develop")
from scholar.
Ok -- this time it works 😄 Thanks
from scholar.
Related Issues (20)
- Years with zero citations cause get_article_cite_history() to fail HOT 3
- get_publications() returns NA for all pubids HOT 2
- author_position() typos in calculation for `Position_Normalized`
- get_publications() `pubid` outputs all `<NA>` HOT 1
- Getting full article citation information (not only the summary)
- get_publication 404 errors HOT 1
- Get scholar does not work for ids with punctuation
- Add new function to create .bib bibliography file for later processing HOT 6
- fix to get_scholar_id HOT 1
- Fix for duplicate profiles HOT 1
- Unclear documentation for swap_initials() within the format_publications function. HOT 1
- Error in predict_h_index() HOT 1
- get_complete_authors returns NA HOT 1
- Error in predict_h_index() HOT 3
- predict.r
- get_coauthors limited to 20 coauthors HOT 1
- add function get_pubs_all_authors - submission HOT 1
- Retrieving field-of-interest/expertise labels HOT 3
- get_publications(id) is not returning pubid HOT 3
- get_article_cite_history(id, pubid) sometimes is not returning HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scholar.