Giter VIP home page Giter VIP logo

Comments (7)

jefferis avatar jefferis commented on July 18, 2024

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.

jefferis avatar jefferis commented on July 18, 2024

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.

wdarling avatar wdarling commented on July 18, 2024

Yes that did the trick! Thanks 👍

from scholar.

wdarling avatar wdarling commented on July 18, 2024

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.

jefferis avatar jefferis commented on July 18, 2024

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.

jefferis avatar jefferis commented on July 18, 2024

Try devtools::install_github("jefferis/scholar@develop")

from scholar.

wdarling avatar wdarling commented on July 18, 2024

Ok -- this time it works 😄 Thanks

from scholar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.