Spaces:
Sleeping
Sleeping
Update OpenAlexNodes.R
Browse files- OpenAlexNodes.R +86 -73
OpenAlexNodes.R
CHANGED
@@ -4,82 +4,95 @@ authorPubNodes <- function(keywords,pub_start_date,pub_end_date){
|
|
4 |
pub_start_date <- pub_start_date
|
5 |
pub_end_date <- pub_end_date
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
23 |
)
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
}
|
28 |
-
|
29 |
-
search_data <- search_engine(keywords,pub_start_date,pub_end_date)
|
30 |
-
|
31 |
-
|
32 |
-
# grab authors and group them according to collaboration
|
33 |
-
authors_collaboration_groups <- list()
|
34 |
-
for (i in 1:nrow(search_data)){
|
35 |
-
authors_collaboration_groups[[i]] <- search_data$author[[i]][2]
|
36 |
-
}
|
37 |
-
|
38 |
-
# grab all authors
|
39 |
-
all_authors <- c()
|
40 |
-
for (i in 1:length(authors_collaboration_groups)) {
|
41 |
-
all_authors <- c(all_authors,authors_collaboration_groups[[i]][[1]])
|
42 |
-
}
|
43 |
-
|
44 |
-
# get length of each authors collaboration
|
45 |
-
authors_length <- c()
|
46 |
-
for(authors in 1:length(authors_collaboration_groups)){
|
47 |
-
authors_length <- c(authors_length,authors_collaboration_groups[[authors]] |> nrow())
|
48 |
-
}
|
49 |
-
|
50 |
-
# grab all publications
|
51 |
-
publications <- list()
|
52 |
-
for (i in 1:nrow(search_data)){
|
53 |
-
publications[[i]] <- rep(search_data$display_name[i], each = authors_length[i])
|
54 |
-
}
|
55 |
-
|
56 |
-
# place all publications in a vector
|
57 |
-
all_publications <- c()
|
58 |
-
for(i in 1:length(publications)){
|
59 |
-
all_publications <- c(all_publications,publications[[i]])
|
60 |
-
}
|
61 |
-
|
62 |
-
# create author_to_publication data frame
|
63 |
-
authors_to_publications <- data.frame(
|
64 |
-
Authors = all_authors,
|
65 |
-
Publications = all_publications
|
66 |
-
)
|
67 |
-
|
68 |
-
# stack the df so that authors and publications
|
69 |
-
# are together as one column
|
70 |
-
stacked_df <- stack(authors_to_publications)
|
71 |
-
stacked_df <- unique.data.frame(stacked_df) # remove duplicate rows
|
72 |
-
stacked_df <- stacked_df[-2] # delete second column in df
|
73 |
-
|
74 |
-
# create author_publications_nodes df
|
75 |
-
author_publication_nodes <- data.frame(
|
76 |
-
Id = 1:nrow(stacked_df),
|
77 |
-
Nodes = stacked_df$values,
|
78 |
-
Label = stacked_df$values
|
79 |
-
)
|
80 |
-
|
81 |
-
|
82 |
-
return(author_publication_nodes)
|
83 |
-
|
84 |
-
|
85 |
-
}
|
|
|
4 |
pub_start_date <- pub_start_date
|
5 |
pub_end_date <- pub_end_date
|
6 |
|
7 |
+
|
8 |
+
if(!is.character(keywords)) {
|
9 |
+
|
10 |
+
shinyalert(
|
11 |
+
title = "Error!",
|
12 |
+
text = "You can only enter text values",
|
13 |
+
closeOnEsc = T,
|
14 |
+
closeOnClickOutside = T,
|
15 |
+
confirmButtonText = "OK",
|
16 |
+
timer = 4000
|
17 |
+
)
|
18 |
+
} else{
|
19 |
+
|
20 |
+
# create search engine function
|
21 |
+
search_engine <- function(keywords,pub_start_date,pub_end_date){
|
22 |
+
suppressPackageStartupMessages(library(openalexR))
|
23 |
+
suppressPackageStartupMessages(library(tidyverse))
|
24 |
+
|
25 |
+
options(openalexR.mailto = "[email protected]")
|
26 |
+
|
27 |
+
# search engine
|
28 |
+
works_search <- oa_fetch(
|
29 |
+
entity = "works",
|
30 |
+
title.search = keywords,
|
31 |
+
cited_by_count = ">50",
|
32 |
+
from_publication_date = pub_start_date,
|
33 |
+
to_publication_date = pub_end_date,
|
34 |
+
options = list(sort = "cited_by_count:desc"),
|
35 |
+
verbose = FALSE
|
36 |
+
)
|
37 |
+
|
38 |
+
return(works_search)
|
39 |
+
|
40 |
+
}
|
41 |
+
|
42 |
+
search_data <- search_engine(keywords,pub_start_date,pub_end_date)
|
43 |
+
|
44 |
+
|
45 |
+
# grab authors and group them according to collaboration
|
46 |
+
authors_collaboration_groups <- list()
|
47 |
+
for (i in 1:nrow(search_data)){
|
48 |
+
authors_collaboration_groups[[i]] <- search_data$author[[i]][2]
|
49 |
+
}
|
50 |
+
|
51 |
+
# grab all authors
|
52 |
+
all_authors <- c()
|
53 |
+
for (i in 1:length(authors_collaboration_groups)) {
|
54 |
+
all_authors <- c(all_authors,authors_collaboration_groups[[i]][[1]])
|
55 |
+
}
|
56 |
+
|
57 |
+
# get length of each authors collaboration
|
58 |
+
authors_length <- c()
|
59 |
+
for(authors in 1:length(authors_collaboration_groups)){
|
60 |
+
authors_length <- c(authors_length,authors_collaboration_groups[[authors]] |> nrow())
|
61 |
+
}
|
62 |
|
63 |
+
# grab all publications
|
64 |
+
publications <- list()
|
65 |
+
for (i in 1:nrow(search_data)){
|
66 |
+
publications[[i]] <- rep(search_data$display_name[i], each = authors_length[i])
|
67 |
+
}
|
68 |
|
69 |
+
# place all publications in a vector
|
70 |
+
all_publications <- c()
|
71 |
+
for(i in 1:length(publications)){
|
72 |
+
all_publications <- c(all_publications,publications[[i]])
|
73 |
+
}
|
74 |
+
|
75 |
+
# create author_to_publication data frame
|
76 |
+
authors_to_publications <- data.frame(
|
77 |
+
Authors = all_authors,
|
78 |
+
Publications = all_publications
|
79 |
)
|
80 |
|
81 |
+
# stack the df so that authors and publications
|
82 |
+
# are together as one column
|
83 |
+
stacked_df <- stack(authors_to_publications)
|
84 |
+
stacked_df <- unique.data.frame(stacked_df) # remove duplicate rows
|
85 |
+
stacked_df <- stacked_df[-2] # delete second column in df
|
86 |
+
|
87 |
+
# create author_publications_nodes df
|
88 |
+
author_publication_nodes <- data.frame(
|
89 |
+
Id = 1:nrow(stacked_df),
|
90 |
+
Nodes = stacked_df$values,
|
91 |
+
Label = stacked_df$values
|
92 |
+
)
|
93 |
+
|
94 |
+
|
95 |
+
return(author_publication_nodes)
|
96 |
|
97 |
}
|
98 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|