Giter VIP home page Giter VIP logo

Comments (3)

mkiang avatar mkiang commented on July 18, 2024 1

I'm pretty sure the issue has to do with a dependency and/or conflict upstream. If I modify get_article_cite_history() such that the only thing I change is to make the rvest namespace explicit for related functions, everything works as intended.

For example, here is the original get_article_cite_history() function:

get_article_cite_history <- function(id, article) {
{
    site <- getOption("scholar_site")
    id <- tidy_id(id)
    url_base <- paste0(site, "/citations?", "view_op=view_citation&hl=en&citation_for_view=")
    url_tail <- paste(id, article, sep = ":")
    url <- paste0(url_base, url_tail)
    res <- get_scholar_resp(url)
    if (is.null(res)) 
        return(NA)
    httr::stop_for_status(res, "get user id / article information")
    doc <- read_html(res)
    years <- doc %>% html_nodes(".gsc_oci_g_t") %>% html_text() %>% 
        as.numeric()
    vals <- doc %>% html_nodes(".gsc_oci_g_al") %>% html_text() %>% 
        as.numeric()
    df <- data.frame(year = years, cites = vals)
    if (nrow(df) > 0) {
        df <- merge(data.frame(year = min(years):max(years)), 
            df, all.x = TRUE)
        df[is.na(df)] <- 0
        df$pubid <- article
    }
    else {
        df$pubid <- vector(mode = mode(article))
    }
    return(df)
}

Here is my modified function (called get_article_cite_history_2()):

get_article_cite_history_2 <- function (id, article) {
    
    site <- getOption("scholar_site")
    id <- tidy_id(id)
    url_base <- paste0(site, "/citations?",
                       "view_op=view_citation&hl=en&citation_for_view=")
    url_tail <- paste(id, article, sep=":")
    url <- paste0(url_base, url_tail)
    
    res <- get_scholar_resp(url)
    httr::stop_for_status(res, "get user id / article information")
    doc <- rvest::read_html(res)
    
    ## Inspect the bar chart to retrieve the citation values and years
    years <- doc %>%
        rvest::html_nodes(".gsc_oci_g_a") %>% 
        rvest::html_attr('href') %>% 
        stringr::str_match("as_ylo=(\\d{4})&") %>% 
        "["(,2) %>% 
        as.numeric()
    vals <- doc %>%
        rvest::html_nodes(".gsc_oci_g_al") %>% 
        rvest::html_text() %>% 
        as.numeric()
    
    df <- data.frame(year = years, cites = vals)
    if(nrow(df)>0) {
        ## There may be undefined years in the sequence so fill in these gaps
        df <- merge(data.frame(year=min(years):max(years)),
                    df, all.x=TRUE)
        df[is.na(df)] <- 0
        df$pubid <- article
    } else {
        # complete the 0 row data.frame to be consistent with normal results
        df$pubid <- vector(mode = mode(article))
    }
    return(df)
}

The output from running each of these:

> scholar::get_article_cite_history("eD9_J3wAAAAJ", "_FxGoFyzp5QC")
Error in data.frame(year = years, cites = vals) : 
  arguments imply differing number of rows: 6, 5
> get_article_cite_history_2("eD9_J3wAAAAJ", "_FxGoFyzp5QC")
  year cites        pubid
1 2016     3 _FxGoFyzp5QC
2 2017     1 _FxGoFyzp5QC
3 2018     0 _FxGoFyzp5QC
4 2019     1 _FxGoFyzp5QC
5 2020     1 _FxGoFyzp5QC
6 2021     5 _FxGoFyzp5QC

A suboptimal workaround right now is to simply replace the get_article_cite_history() function with the one I made above after calling in library(scholar) but this seems like something a dev can patch quickly.

from scholar.

TerrestrialEcologyLabSERC avatar TerrestrialEcologyLabSERC commented on July 18, 2024

I am having the same issue!

get_article_cite_history("QtuhiVMAAAAJ", "IjCSPb-OGe4C")

Error in data.frame(year = years, cites = vals) : 
  arguments imply differing number of rows: 16, 15

Have confirmed by looking at the google scholar page that it is articles that have years with no citations that is the problem.

Thank you so much!

from scholar.

rmwaterhouse avatar rmwaterhouse commented on July 18, 2024

Also having the same issue ... took a while to figure it out - any year with zero citations causes get_article_cite_history to die.

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.