Giter VIP home page Giter VIP logo

Comments (6)

GuangchuangYu avatar GuangchuangYu commented on July 18, 2024 1

incorporated, see YuLab-SMU@03a9394#diff-3fc538c4fa03e2b111fe20ab306291513d8d306fb319e4ea6cb64b671f7f014e.

from scholar.

GuangchuangYu avatar GuangchuangYu commented on July 18, 2024 1

try this:

---
output: html_document
---


```{r  results = "asis"}
scholar::format_publications("NrfwEncAAAAJ", "R Thériault") |> cat(sep='\n\n')
```


```{r  results = "asis"}
scholar::format_publications("NrfwEncAAAAJ", "R Thériault") 
```

```{r  results = "asis"}
scholar::format_publications("NrfwEncAAAAJ", "R Thériault") |> print(quote=FALSE)
```

from scholar.

GuangchuangYu avatar GuangchuangYu commented on July 18, 2024 1

You are welcome to create a PR for the vignette.

from scholar.

rempsyc avatar rempsyc commented on July 18, 2024

In the meanwhile, here is a workaround and function that give decent results. Reproducible rmarkdown example:

---
output: html_document
---

# Publications

```{r, results = "asis", echo = FALSE, message = FALSE}
format.authors <- function(scholar.profile, author.name) {
  library(dplyr)

  swap_initials <- function(author.name) {
    sub("(.*) (.*)", "\\2, \\1.", trimws(author.name))
  }

  pubs <- scholar::get_publications(scholar.profile)
  pubs %>% 
    strsplit(x = .$author, split = ",") -> pubs2
  lapply(pubs2, function(x) {
    x <- swap_initials(x)
    x[length(x)] <- paste0("& ", x[length(x)])
    x <- paste0(x, collapse = ", ")
    ifelse(startsWith(x, "& "), sub("& ", "", x), x)
    }
    ) -> pubs$author
  
  author.name2 <- swap_initials(author.name)
  
  pubs %>% 
    arrange(desc(year)) %>%
    mutate(journal = paste0("*", journal, "*"),
           Publications = paste0(author, " (", year, "). ", 
                                 title, ". ", journal, ". ", 
                                 number),
           Publications = gsub(author.name2, paste0("**", author.name2, "**"), Publications)) %>% 
    select(Publications)
}

pubs <- format.authors("NrfwEncAAAAJ", "R Thériault")

cat(unlist(pubs), sep = "\\\n \\\n")
```

pubs

However, this workaround won't work if you are indenting your publications in vitae/LaTeX: the other references will all be indented by LaTex as if they were the same unit/paragraph. Using the following to indent:

\setlength{\parindent}{-0.2in}
\setlength{\leftskip}{0.2in}

pubs2


Despite the indenting problem, would you consider adding this function to scholar?

from scholar.

rempsyc avatar rempsyc commented on July 18, 2024

Amazing!

One reflection I had was whether we should include within the function output the following bit for proper rmarkdown formatting:

cat(unlist(pubs), sep = "\\\n \\\n")

If not included the full rmarkdown workflow would need to be something like:

scholar::format_publications("NrfwEncAAAAJ", "R Thériault") |> 
  unlist() |> 
  cat(sep = "\\\n \\\n")

Or should we let the user do that? I think adding it would be one fewer step for the user using rmarkdown. However, it would not be in a proper format for further manipulation outside of rmarkdown (and not consistent with other functions). Yet, I don't know how people would use this outside of rmarkdown. Perhaps only to make some manual edits if the function fails in some aspects.

Second, be aware that there is a minor issue that my function does not deal with yet, which is the situation of having multiple initials. For example, it formats the initials SA as "SA.", whereas technically according to APA style it should be "S. A.". But that's probably the lowest possible priority. If I find a fix eventually I'll come back to post it here.

from scholar.

rempsyc avatar rempsyc commented on July 18, 2024

Awesome, the first one looks good for APA style, and the last one I think could be useful for other styles that use numbering. I think it would be neat to eventually have a vignette (or blog post) for this.

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.