Skip to content

Instantly share code, notes, and snippets.

@dubsnipe
Created July 24, 2023 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubsnipe/84eaefb5ce2378e8c1759491cf56b519 to your computer and use it in GitHub Desktop.
Save dubsnipe/84eaefb5ce2378e8c1759491cf56b519 to your computer and use it in GitHub Desktop.
require(bibtex)
library(rvest)
library(dplyr)
require(stringr)
require(RefManageR)
require(lubridate)
bib <- read.bib(file = "items.bib")
bib_csv <- read.csv("items.csv")
f_bib <- format(bib)
f_bib <- str_replace_all(f_bib, "_", "''")
f_bib <- str_replace_all(f_bib, "\n", "")
f_bib <- str_replace_all(f_bib, "\\*", "'''")
bib_csv$clean_notes <- gsub("<.*?>", "", bib_csv$Notes)
bib_csv$clean_notes <- paste("*", gsub("\\s{2,}", "\n* ", str_trim(bib_csv$clean_notes)))
item_types_dirty <- c("journalArticle", "webpage", "bookSection", "magazineArticle", "book", "forumPost", "report", "conferencePaper", "thesis", "blogPost")
item_types_clean <- c("Journal article", "Web page", "Book section", "Magazine article", "Book", "Forum post", "Report", "Conference paper", "Thesis", "Blog post")
item_types <- bind_cols(dirty=item_types_dirty, clean=item_types_clean)
for (i in 1:nrow(item_types)){
bib_csv$Item.Type <- ifelse(bib_csv$Item.Type == item_types$dirty[i], item_types$clean[i], bib_csv$Item.Type)
}
# Create the review
final_vector <- vector()
for (i in 1:nrow(bib_csv)){
final_vector <- c(final_vector, paste0("===", bib_csv$Title[i], "===\n{{Card|title = '''Source''': ", Cite(bib[i]),
"<ref>", f_bib[i],
"</ref>|content = *'''Item type''': ",
bib_csv$Item.Type[i],
"\n*'''Retrieved on''': ", date(bib_csv$Date.Added[i]), "}}",
"\n====Notes====\n", str_trim(bib_csv$clean_notes[i]),
"\n"))
}
final_text <- paste0(final_vector, collapse="")
final_text <- paste0("This is an introductory text about the goal and scope of the literature review, for example, the parent page (in this case, [[{{BASEPAGENAME}}]]) and the search keywords.\n== Literature ==\n", final_text, "== References ==\n{{Reflist}}")
write.table(final_text, "clipboard", sep="\n", quote=FALSE, row.names=FALSE, col.names=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment