-
Notifications
You must be signed in to change notification settings - Fork 2
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
Chapter 2 code review #3
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
### Code to exemplify Part 2 with Xiaoxia's query | ||
|
||
# Install and load packages ---- | ||
## List pacakges used in the script | ||
packages <- c("rscopus", "RefManageR", "dplyr", "stringr", "bibtex", | ||
"revtools", "remotes", "igraph", "litsearchr", | ||
"PRISMA2020", "PRISMAstatement") | ||
|
||
## Load packages and install them if needed | ||
for (package in packages) { | ||
if (!require(package, character.only = TRUE)) { | ||
if (package == "litsearchr") remotes::install_github("elizagrames/litsearchr", ref="main") | ||
else install.packages(package) | ||
} | ||
} | ||
|
||
# Section 1: Retrieve references from WoS and Scopus (Shuyu) ---- | ||
|
||
# Section 1: Retrieve references from WoS and Scopus (Shuyu) | ||
# install and library packages for retrieving references from scopus | ||
install.packages("rscopus") | ||
library(rscopus) | ||
install.packages("RefManageR") | ||
library(RefManageR) | ||
install.packages("dplyr") | ||
library(dplyr) | ||
install.packages("bibtex") | ||
library(bibtex) | ||
|
||
# Retrieving references from scopus: | ||
# Set your API key, if you do not have, please go to the website of Elsevier Developer Portal: https://dev.elsevier.com/ to apply, and you will get the key. | ||
options(elsevier_api_key = Your_scopus_api_key) | ||
# Retrieving references from Scopus: | ||
## Set API key by running Sys.setenv(Your_scopus_api_key = "YOUR_API_KEY_HERE") | ||
## in the console. If you do not have an API key, get one from | ||
## https://dev.elsevier.com/ | ||
options(elsevier_api_key = Sys.getenv("Your_scopus_api_key")) | ||
|
||
# Set your research query | ||
query <- "( ( ( TITLE ( govern* OR state OR decision-making OR policy-making OR stakeholder OR participat* ) ) AND ( TITLE-ABS-KEY ( impact OR outcome OR result OR differentiation OR consequence OR change OR transformation OR role ) ) ) OR ( TITLE-ABS-KEY ( governance W/0 ( mode OR model OR process ) ) ) ) AND | ||
|
@@ -24,7 +30,8 @@ query <- "( ( ( TITLE ( govern* OR state OR decision-making OR policy-making OR | |
( LIMIT-TO ( DOCTYPE , \"ar\" ) ) AND | ||
( LIMIT-TO ( LANGUAGE , \"English\" ) )" | ||
|
||
# search on scopus if you get the api key, you can modify the max_count for each searching | ||
# Search Scopus | ||
## You can modify the max_count for each search | ||
if (have_api_key()) { | ||
res <- scopus_search(query = query, max_count = 200, count = 10) | ||
search_results <- gen_entries_to_df(res$entries) | ||
|
@@ -57,7 +64,7 @@ transposed_results_df <- t(results_df) | |
write.csv(transposed_results_df, "scopus_api_results.csv", row.names = FALSE) | ||
df <- read.csv("scopus_api_results.csv") | ||
|
||
# Example dataframe with additional fields | ||
# Example data frame with additional fields | ||
data <- data.frame( | ||
Author = df$dc.creator, | ||
Title = df$dc.title, | ||
|
@@ -69,7 +76,7 @@ data <- data.frame( | |
DOI = df$prism.doi | ||
) | ||
|
||
# Convert the dataframe to a BibEntryList object | ||
# Convert the data frame to a BibEntryList object | ||
# Create a list of BibEntry objects | ||
bib_entries <- lapply(1:nrow(data), function(i) { | ||
BibEntry( | ||
|
@@ -95,7 +102,6 @@ bib_text <- unlist(bib_texts, use.names = FALSE) | |
# Write BibTeX file | ||
writeLines(bib_text, "scopus_references.bib") | ||
|
||
|
||
# Retrieving references from web of science: | ||
# wosr package is not working now? l tried many times with the username and password but could not connect to the server. | ||
|
||
|
@@ -144,6 +150,9 @@ bib_data$Volume <- gsub("'", "", bib_data$Volume) | |
bib_data$Number <- gsub("'", "", bib_data$Number) | ||
bib_data$Pages <- gsub("'", "", bib_data$Pages) | ||
|
||
# Remove entries without a title | ||
bib_data <- bib_data[bib_data$Title != "", ] | ||
|
||
Comment on lines
+153
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hre I removed the entries without a title. That seems to have caused issues later in the BibEntry list. |
||
# Create a list of BibEntry objects | ||
# (l got problems that l cannot extract title from those cases:title="'Inner-city is not the place for social housing' - State-led gentrification in Lodz" and '"Freeways without futures": Urban highway removal in the United States and Spain as socio-ecological fix?' ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does my addition above solve this issue or is this something else? |
||
bib_wos_entries <- lapply(1:nrow(bib_data), function(i) { | ||
|
@@ -171,7 +180,6 @@ bib_wos_text <- unlist(bib_wos_texts, use.names = FALSE) | |
writeLines(bib_wos_text, "wos_references.bib") | ||
|
||
# Method2: create bib file with multiple txt files | ||
library(stringr) | ||
|
||
# Function to read content from a text file and extract information | ||
read_and_extract <- function(file_path) { | ||
|
@@ -224,6 +232,9 @@ file_paths <- c("api_response_page1.txt", "api_response_page2.txt", "api_respons | |
# Read data from each file and combine them into one data frame | ||
combined_data <- do.call(rbind, lapply(file_paths, read_and_extract)) | ||
|
||
# Remove entries without a title | ||
combined_data <- combined_data[combined_data$Title != "", ] | ||
|
||
Comment on lines
+235
to
+237
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, entries without title removed. |
||
# Create a list of BibEntry objects | ||
bib_entries <- lapply(1:nrow(combined_data), function(i) { | ||
BibEntry( | ||
|
@@ -249,16 +260,9 @@ bib_text <- unlist(bib_texts, use.names = FALSE) | |
# Write BibTeX file | ||
writeLines(bib_text, "wos_references.bib") | ||
|
||
# Section 2: Combine tables, deduplicate references and summarise (Kyri?) | ||
library(revtools) | ||
|
||
# Section 3: Suggest new keywords (Clementine) | ||
# Section 2: Combine tables, deduplicate references and summarise (Kyri?) ---- | ||
|
||
# install.packages("remotes") | ||
# library(remotes) | ||
# install_github("elizagrames/litsearchr", ref="main") | ||
library(litsearchr) | ||
library(igraph) | ||
# Section 3: Suggest new keywords (Clementine) ---- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I so not have the data for this section, so I cannot run it. |
||
|
||
#Import .bib or .ris database | ||
|
||
|
@@ -322,14 +326,8 @@ litsearchr::write_search(grouped, | |
verbose = TRUE, | ||
closure = "left") | ||
|
||
# Section 4: build PRISMA figure (Xiaoxia) | ||
library(PRISMA2020) | ||
|
||
|
||
## ----prisma-------------------------------------------------------------- | ||
#install.packages("PRISMAstatement") | ||
library(PRISMAstatement) | ||
|
||
# Section 4: build PRISMA figure (Xiaoxia) ---- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this section is unnecessarily long. It would be enough to show a full example with all/most customisation and refer the reader to the package documentation. |
||
## Prisma | ||
prisma(found = 750, | ||
found_other = 123, | ||
no_dupes = 776, | ||
|
@@ -341,7 +339,10 @@ prisma(found = 750, | |
quantitative = 319, | ||
width = 800, height = 800) | ||
|
||
## ----prismadupesbox------------------------------------------------------ Ideally, you will stick closely to the PRISMA statement, but small deviations are common. PRISMAstatement gives the option of adding a box which simply calculates the number of duplicates removed. | ||
## Prismadupesbox | ||
### Ideally, you will stick closely to the PRISMA statement, but small deviations | ||
### are common. PRISMAstatement gives the option of adding a box which simply | ||
### calculates the number of duplicates removed. | ||
prisma(found = 750, | ||
found_other = 123, | ||
no_dupes = 776, | ||
|
@@ -353,24 +354,29 @@ prisma(found = 750, | |
quantitative = 319, | ||
extra_dupes_box = TRUE) | ||
|
||
## ----labels-------------------------------------------------------------- You can also change the labels, but you will have to insert the number for any label you chang | ||
## Labels | ||
### You can also change the labels, but you will have to insert the number for | ||
### any label you change | ||
prisma(1000, 20, 270, 270, 10, 260, 20, 240, 107, | ||
labels = list(found = "FOUND", found_other = "OTHER")) | ||
|
||
## ----errors and warnings------------------------------------------------- | ||
## Errors and warnings | ||
tryCatch( | ||
prisma(1, 2, 3, 4, 5, 6, 7, 8, 9), | ||
error = function(e) e$message) | ||
|
||
prisma(1000, 20, 270, 270, 10, 260, 19, 240, 107, | ||
width = 100, height = 100) | ||
|
||
prisma(1000, 20, 270, 270, 269, 260, 20, 240, 107, | ||
width = 100, height = 100) | ||
|
||
## ----font_size----------------------------------------------------------- | ||
## Font size | ||
prisma(1000, 20, 270, 270, 10, 260, 20, 240, 107, font_size = 6) | ||
prisma(1000, 20, 270, 270, 10, 260, 20, 240, 107, font_size = 60) | ||
|
||
## ----prismadpi1, fig.cap="just set width and height"--------------------- | ||
## Prismadpi1, | ||
### just set width and height | ||
prisma(found = 750, | ||
found_other = 123, | ||
no_dupes = 776, | ||
|
@@ -382,7 +388,8 @@ prisma(found = 750, | |
quantitative = 319, | ||
width = 200, height = 200) | ||
|
||
## ----prismadpi2, fig.cap="same width and height but DPI increased to 300"---- | ||
## Prismadpi2 | ||
### same width and height but DPI increased to 300 | ||
prisma(found = 750, | ||
found_other = 123, | ||
no_dupes = 776, | ||
|
@@ -395,7 +402,8 @@ prisma(found = 750, | |
width = 200, height = 200, | ||
dpi = 300) | ||
|
||
## ----prismadpi3, fig.cap="same width and height but DPI decreased to 36"---- | ||
## Prismadpi3 | ||
### same width and height but DPI decreased to 36 | ||
prisma(found = 750, | ||
found_other = 123, | ||
no_dupes = 776, | ||
|
@@ -408,7 +416,7 @@ prisma(found = 750, | |
width = 200, height = 200, | ||
dpi = 36) | ||
|
||
## ----prismapdf, echo = TRUE, eval = FALSE-------------------------------- | ||
## Prismapdf | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this section be removed? |
||
# prsm <- prisma(found = 750, | ||
# found_other = 123, | ||
# no_dupes = 776, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved all package loading and installation to the beginning of the script. Packages are only installed if they are not present on the user's system.