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 in predict_h_index() #118

Open
mgclaros opened this issue Dec 9, 2022 · 3 comments
Open

Error in predict_h_index() #118

mgclaros opened this issue Dec 9, 2022 · 3 comments

Comments

@mgclaros
Copy link

mgclaros commented Dec 9, 2022

I have updated my R 4.2.2 in my aarch64-apple-darwin20 and I always obtain the same error:
predict_h_index("vamErfkAAAAJ")
Error in if (is.na(h)) return(NA) : the condition has length > 1

I located the problem in the function when

h <- get_profile(id)
is.na(h)
id name affiliation total_cites h_index i10_index fields
FALSE FALSE FALSE FALSE FALSE FALSE FALSE
homepage coauthors available not_available
FALSE FALSE FALSE FALSE

And it is said that you should use ifelse in such a case. Would you debug it?

@bappa10085
Copy link

Installing the development version solves the error like

remotes::install_github("jkeirstead/scholar")

@ian-adams
Copy link

Full local function to fix this error @(mgclaros)

predict_h_index <- function(id, journals = NULL) {
    id <- tidy_id(id)

    # Getting the h-index and checking for NA
    h <- get_profile(id)$h_index
    if (is.na(h)) return(NA)

    n <- get_num_articles(id) # number of articles written
    y <- as.numeric(format(Sys.Date(), "%Y")) - get_oldest_article(id)
    j <- get_num_distinct_journals(id)

    # Handle optional journals parameter
    if (is.null(journals)) {
        q <- get_num_top_journals(id)
    } else {
        q <- get_num_top_journals(id, journals)
    }

    # Regression coefficients
    coefs <- c(
        1, 0.760, 0.373, 0.967, -0.069, 0.018, 0.033,
        2, 1.413, 0.781, 0.936, -0.132, 0.018, 0.064,
        3, 2.227, 1.105, 0.903, -0.193, 0.027, 0.096,
        4, 3.196, 1.386, 0.871, -0.274, 0.039, 0.145,
        5, 3.997, 1.578, 0.858, -0.345, 0.063, 0.198,
        6, 4.752, 1.671, 0.817, -0.377, 0.117, 0.282,
        7, 5.741, 1.761, 0.761, -0.420, 0.170, 0.394,
        8, 6.531, 1.796, 0.669, -0.420, 0.252, 0.508,
        9, 7.482, 1.653, 0.561, -0.415, 0.383, 0.629,
        10, 8.734, 1.326, 0.478, -0.411, 0.522, 0.823
    )
    coefs.m <- matrix(coefs, nrow=10, byrow=TRUE)
    coefs <- coefs.m[,-1]
    vals <- c(1, sqrt(n), h, y, j, q)

    # Calculate the h-index predictions
    h.pred <- coefs %*% vals
    h.vals <- c(h, h.pred)

    # Check for sensible values
    standard.warning <- "You're probably not a neuroscientist. Please read the documentation for information on the limitations of this function."
  
    if (any(diff(h.vals) < 0)) {
        warning(paste0("Decreasing h-values predicted. ", standard.warning))
    }

    if (any(h.vals < 0)) {
        warning(paste0("Negative h-values predicted. ", standard.warning))
    }
  
    return(data.frame(years_ahead = 0:10, h_index = h.vals))
}

@mgclaros
Copy link
Author

mgclaros commented Dec 4, 2023

The development version did not function, but the 'alternative' the function worked fine :-) Thanks!

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