-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.Rhistory
512 lines (512 loc) · 17.5 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
usethis::use_pkgdown()
library(pkgdown)
build_site()
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(pkgdown)
build_site()
library(spiR)
build_site()
library(spiR)
build_site()
library(spiR)
library(spiR)
build_site()
library(spiR)
#' sqs_spi_data
#'
#' @description This function allows you to find and display the Social Progress Index data according to the selected parameters.
#' If no arguments are filed, all data will be displayed.
#'
#' @param country country Countries' ISO code.
#' @param years Years for which you want data.
#' @param indicators Indicators from the Social Progress Index.
#'
#' @import gsheet
#' @import dplyr
#' @import reshape2
#'
#' @return Data for the country, indicator and year requested
#' @export
#'
#' @seealso \code{\link{sqs_spi_indicator}} for the SPI's indicator symbol and \code{\link{sqs_spi_country}} for the country's ISO code.
#'
#' @examples
#' myData<- sqs_spi_data(country = c("USA", "FRA"), years = "2018", )
#' myData<- sqs_spi_data(country = c("USA", "FRA"), year = c("2018", "2019"), indicators = "SPI")
#' myData<- sqs_spi_data("USA", "2019", c("SPI", "FOW"))
#' myData<- sqs_spi_data(, "2018", )
#' myData<- sqs_spi_data("USA", "2017", )
#' myData<- sqs_spi_data("USA", , )
#' myData<- sqs_spi_data(, , )
#' myData<- sqs_spi_data()
#'
#'
#
# Function 1: Data collection
spi_data <- gsheet::gsheet2tbl("https://docs.google.com/spreadsheets/d/1_nQ9mQU_4J0KDRc4_TMzTsJHMYBqLwwnPaMC5BVhkGc/edit#gid=0")
# Function 2: Indicators' symbols query
# If the user does not know the code of an indicator, s.he has access to the answer in natural language through this query
#' sqs_spi_indicator
#'
#' @description This function allows you to find and search the right indicator code from the Social Progress Index you want to use.
#' If no argument is filed, all indicators will be displayed.
#' @param indicators An indicator from the Social Progress Index.
#'
#' @return Indicator code from the Social Progress Index.
#' @export
#' @seealso \code{\link{sqs_spi_country}} for the SPI's country code and \code{\link{sqs_spi_data}} to collect data when you have both indicator and country code.
#'
#' @examples
#'myIndicator <- sqs_spi_indicator()
#'myIndicator <- sqs_spi_indicator(indicators = "mortality")
#'myIndicator <- sqs_spi_indicator("mortality")
#'
sqs_spi_indicator <- function(indicators) {
spi_indicators_natural_language <- gsheet::gsheet2tbl("https://docs.google.com/spreadsheets/d/1_nQ9mQU_4J0KDRc4_TMzTsJHMYBqLwwnPaMC5BVhkGc/edit#gid=400714513")
if (missing(indicators)) {
spi_indicators_natural_language
} else {
spi_indicators_natural_language[grep(indicators, spi_indicators_natural_language$indicator_name), ]
}
}
# Function 3: Countries' code reconciliation
# If the user does not know the ISO code of a country, s.he has access to the answer in natural language through this query
#' sqs_spi_country
#' @description This function allows you to find and search the right country code associated with the Social Progress Index's Data.
#' If no argument is filed, all indicators will be displayed.
#'
#' @param country The name of the country starting with a capital letter.
#'
#' @return Country's ISO code.
#' @export
#' @seealso \code{\link{sqs_spi_indicator}} for the SPI's indicators and \code{\link{sqs_spi_data}} to collect data when you have both indicator and country code.
#' @examples
#'mycountry <- sqs_spi_country()
#'mycountry <- sqs_spi_country(country = "Canada")
#'mycountry <- sqs_spi_country("Canada")
#'
sqs_spi_country <- function(country) {
spi_countries_natural_language <- unique(spi_data[, 1:2])
if (missing(country)) {
spi_countries_natural_language
} else {
spi_countries_natural_language[grep(country, spi_countries_natural_language$countryName), ]
}
}
data_long <- reshape2::melt(spi_data,
# ID variables - all the variables to keep but not split apart on
id.vars = c("countryName", "code", "year"),
# The source columns
measure.vars = colnames(spi_data)[6:ncol(spi_data)],
# Name of the destination column that will identify the original
# column that the measurement came from
#variable.name = "var_indicator",
#value.name = "value"
)
base::names(data_long) = c("countryName", "var_code", "var_year", "var_indicator", "value")
# Creating the default values for the function query
# IF an entry is missing, all the observations of this variable will be displayed
data_long_country <- base::unique(data_long[, 2])
data_long_year <- base::unique(data_long[, 3])
data_long_indicator <- base::unique(data_long[, 4])
sqs_spi_data <- function(country = data_long_country,
years = data_long_year,
indicators = data_long_indicator) {
out <- dplyr::filter(data_long,
var_code %in% country,
var_year %in% years,
var_indicator %in% indicators)
return(out)
}
#' sqs_spi_data
#'
#' @description This function allows you to find and display the Social Progress Index data according to the selected parameters.
#' If no arguments are filed, all data will be displayed.
#'
#' @param country country Countries' ISO code.
#' @param years Years for which you want data.
#' @param indicators Indicators from the Social Progress Index.
#'
#' @import gsheet
#' @import dplyr
#' @import reshape2
#'
#' @return Data for the country, indicator and year requested
#' @export
#'
#' @seealso \code{\link{sqs_spi_indicator}} for the SPI's indicator symbol and \code{\link{sqs_spi_country}} for the country's ISO code.
#'
#' @examples
#' myData<- sqs_spi_data(country = c("USA", "FRA"), years = "2018", )
#' myData<- sqs_spi_data(country = c("USA", "FRA"), year = c("2018", "2019"), indicators = "SPI")
#' myData<- sqs_spi_data("USA", "2019", c("SPI", "FOW"))
#' myData<- sqs_spi_data(, "2018", )
#' myData<- sqs_spi_data("USA", "2017", )
#' myData<- sqs_spi_data("USA", , )
#' myData<- sqs_spi_data(, , )
#' myData<- sqs_spi_data()
#'
#'
#
# Function 1: Data collection
spi_data <- gsheet::gsheet2tbl("https://docs.google.com/spreadsheets/d/1_nQ9mQU_4J0KDRc4_TMzTsJHMYBqLwwnPaMC5BVhkGc/edit#gid=0")
data_long <- reshape2::melt(spi_data,
# ID variables - all the variables to keep but not split apart on
id.vars = c("countryName", "code", "year"),
# The source columns
measure.vars = colnames(spi_data)[6:ncol(spi_data)],
# Name of the destination column that will identify the original
# column that the measurement came from
#variable.name = "var_indicator",
#value.name = "value"
)
base::names(data_long) = c("countryName", "var_code", "var_year", "var_indicator", "value")
# Creating the default values for the function query
# IF an entry is missing, all the observations of this variable will be displayed
data_long_country <- base::unique(data_long[, 2])
data_long_year <- base::unique(data_long[, 3])
data_long_indicator <- base::unique(data_long[, 4])
sqs_spi_data <- function(country = data_long_country,
years = data_long_year,
indicators = data_long_indicator) {
out <- dplyr::filter(data_long,
var_code %in% country,
var_year %in% years,
var_indicator %in% indicators)
return(out)
}
# Function 2: Indicators' symbols query
# If the user does not know the code of an indicator, s.he has access to the answer in natural language through this query
#' sqs_spi_indicator
#'
#' @description This function allows you to find and search the right indicator code from the Social Progress Index you want to use.
#' If no argument is filed, all indicators will be displayed.
#' @param indicators An indicator from the Social Progress Index.
#'
#' @return Indicator code from the Social Progress Index.
#' @export
#' @seealso \code{\link{sqs_spi_country}} for the SPI's country code and \code{\link{sqs_spi_data}} to collect data when you have both indicator and country code.
#'
#' @examples
#'myIndicator <- sqs_spi_indicator()
#'myIndicator <- sqs_spi_indicator(indicators = "mortality")
#'myIndicator <- sqs_spi_indicator("mortality")
#'
sqs_spi_indicator <- function(indicators) {
spi_indicators_natural_language <- gsheet::gsheet2tbl("https://docs.google.com/spreadsheets/d/1_nQ9mQU_4J0KDRc4_TMzTsJHMYBqLwwnPaMC5BVhkGc/edit#gid=400714513")
if (missing(indicators)) {
spi_indicators_natural_language
} else {
spi_indicators_natural_language[grep(indicators, spi_indicators_natural_language$indicator_name), ]
}
}
# Function 3: Countries' code reconciliation
# If the user does not know the ISO code of a country, s.he has access to the answer in natural language through this query
#' sqs_spi_country
#' @description This function allows you to find and search the right country code associated with the Social Progress Index's Data.
#' If no argument is filed, all indicators will be displayed.
#'
#' @param country The name of the country starting with a capital letter.
#'
#' @return Country's ISO code.
#' @export
#' @seealso \code{\link{sqs_spi_indicator}} for the SPI's indicators and \code{\link{sqs_spi_data}} to collect data when you have both indicator and country code.
#' @examples
#'mycountry <- sqs_spi_country()
#'mycountry <- sqs_spi_country(country = "Canada")
#'mycountry <- sqs_spi_country("Canada")
#'
sqs_spi_country <- function(country) {
spi_countries_natural_language <- unique(spi_data[, 1:2])
if (missing(country)) {
spi_countries_natural_language
} else {
spi_countries_natural_language[grep(country, spi_countries_natural_language$countryName), ]
}
}
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
aa <- sqs_spi_data()
aa <- sqs_spi_data()
View(aa)
ab <- sqs_spi_indicator()
View(ab)
as <- sqs_spi_data("USA",2016)
View(as)
aass <- sqs_spi_country("Canada","Germany","Iceland")
aass <- sqs_spi_country("Canada")
View(aass)
usethis::use_appveyor()
library(pkgdown)
build_site()
library(spiR)
library(devtools)
check_win_release()
build_site()
build_site()
library(spiR)
library(spiR)
use_cran_comments()
library(spiR)
rela
e
release()
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(spiR)
library(pkgdown)
build_site()
library(spiR)
library(spiR)
build_site()
library(spiR)
build_site()
library(spiR)
library(pkgdown)
build_site()
library(devtools)
submit_cran()
library(spiR)
library(spiR)
library(spiR)
build_site()
library(devtools)
build_site()
pkgdown::build_site()
library(spiR)
pkgdown::build_site()
pkgdown::build_site()
devtools::submit_cran()
pkgdown::build_site()
library(spiR)
devtools::submit_cran()
library(spiR)
library(spiR)
pkgdown::build_site()
devtools::submit_cran()
pkgdown::build_site()
pkgdown::build_site()
library(spiR)
pkgdown::build_site()
devtools::submit_cran()
pkgdown::build_site()
pkgdown::build_site()
pkgdown::build_site()
library(spiR)
pkgdown::build_site()
# Loading data
url <- paste0("https://warin.ca/datalake/spiR/SPI_data.csv")
path <- file.path(tempdir(), "temp.csv")
curl::curl_download(url, path)
csv_file <- file.path(paste0(tempdir(), "/temp.csv"))
SPI_data <- readr::read_csv(csv_file)
url <- paste0("https://warin.ca/datalake/spiR/SPI_indicator.csv")
path <- file.path(tempdir(), "temp.csv")
curl::curl_download(url, path)
csv_file <- file.path(paste0(tempdir(), "/temp.csv"))
SPI_indicator <- readr::read_csv(csv_file)
spi_country <- base::unique(SPI_data$country_code)
spi_year <- base::unique(SPI_data$year)
spi_indicator <- base::unique(SPI_data$indicator_code)
spir_data <- function(country = spi_country,
years = spi_year,
indicators = spi_indicator) {
country_code <- year <- indicator_code <- NULL
out <- dplyr::filter(SPI_data,
country_code %in% country,
year %in% years,
indicator_code %in% indicators)
return(out)
}
spir_indicator <- function(indicators) {
spi_indicators_natural_language <- SPI_indicator
if (missing(indicators)) {
spi_indicators_natural_language
} else {
spi_indicators_natural_language[grep(indicators, spi_indicators_natural_language$indicator_name, ignore.case = TRUE), ]
}
}
spir_country <- function(country) {
spi_countries_natural_language <- unique(SPI_data[, 2:3])
if (missing(country)) {
spi_countries_natural_language
} else {
spi_countries_natural_language[grep(country, spi_countries_natural_language$country_name, ignore.case = TRUE), ]
}
}
spir_visual <- function(chart = "bar_1", indicator = "SPI", years = max(SPI_data$year), title = TRUE){
year <- value <- indicator_code <- country_name <- country_code <- NULL
if(years > 2020 | years < 2011){
stop("no available data for the requested year")
}
if(chart == "bar_1"){
barchart1 <- SPI_data
barchart1 <- dplyr::filter(barchart1, year == years)
barchart1 <- dplyr::filter(barchart1, indicator_code == indicator)
barchart1 <- dplyr::arrange(barchart1, desc(value))
countries <- barchart1[1:9, 3]
countries <- countries$country_code
barchart1 <- dplyr::filter(barchart1, country_code %in% countries)
barchart1$country_name <- factor(barchart1$country_name, levels = unique(barchart1$country_name)[order(barchart1$value)])
barchart1$value <- format(round(barchart1$value, 2), nsmall = 2)
if(title == TRUE){
ggplot2::ggplot(data = barchart1, aes(x = country_name, y = value, fill = country_name)) +
ggplot2::geom_col() +
ggplot2::geom_text(aes(label=value), vjust=0.2, hjust = 1.1, colour = "white", size = 3.2, fontface = "bold") +
ggplot2::ylab("") +
ggplot2::xlab("") +
ggplot2::ggtitle(paste(unique(barchart1$indicator_name), "in", years)) +
ggplot2::theme_minimal() +
ggplot2::guides(fill=FALSE) +
ggsci::scale_fill_uchicago() +
ggplot2::theme(legend.position="none", plot.title = element_text(size=12)) +
ggplot2::labs(fill = "Countries", caption="Source: Warin (2020) & Social Progress Index.") +
ggplot2::coord_flip() +
ggplot2::theme(axis.title.x=element_blank(),
axis.ticks.x=element_blank(),
axis.text.x=element_blank())
} else {
ggplot2::ggplot(data = barchart1, aes(x = country_name, y = value, fill = country_name)) +
ggplot2::geom_col() +
ggplot2::geom_text(aes(label=value), vjust=0.2, hjust = 1.1, colour = "white", size = 3.2, fontface = "bold") +
ggplot2::ylab("") +
ggplot2::xlab("") +
ggtitle("") +
ggplot2::theme_minimal() +
ggplot2::guides(fill=FALSE) +
ggsci::scale_fill_uchicago() +
ggplot2:: theme(legend.position="none", plot.title = element_text(size=12)) +
ggplot2::labs(fill = "Countries", caption="Source: Warin (2020) & Social Progress Index.") +
ggplot2::coord_flip() +
ggplot2::theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())
}
} else if(chart == "line_1"){
linechart1 <- SPI_data
linechart1 <- dplyr::filter(linechart1, indicator_code == indicator)
linechart1 <- dplyr::arrange(linechart1, desc(year), desc(value))
countries <- linechart1[1:6, 3]
countries <- countries$country_code
linechart1 <- dplyr::filter(linechart1, country_code %in% countries)
linechart1$year <- lubridate::ymd(linechart1$year, truncated = 2L)
if(title == TRUE){
ggplot2::ggplot(data = linechart1, aes(x = year, y = value, color = country_name, shape = country_name)) +
ggplot2::geom_line() +
ggplot2::geom_point(size = 2, stroke = 1) +
ggplot2::ylab("") +
ggplot2:: xlab("") +
ggplot2::ggtitle(paste0(unique(linechart1$indicator_name), ": \nEvolution of the ", max(SPI_data$year), " most represented countries")) +
ggplot2::theme_minimal() +
ggplot2::guides(fill=FALSE) +
ggsci::scale_color_uchicago() +
ggplot2::theme(legend.position="right", plot.title = element_text(size=12)) +
ggplot2::labs(shape = "Countries", color = "Countries", caption="Source: Warin (2020) & Social Progress Index.")
} else {
ggplot2::ggplot(data = linechart1, aes(x = year, y = value, color = country_name, shape = country_name)) +
ggplot2::geom_line() +
ggplot2::ylab("") +
ggplot2::xlab("") +
ggplot2::ggtitle("") +
ggplot2::theme_minimal() +
ggplot2::guides(fill=FALSE) +
ggplot2::geom_point(size = 2, stroke = 1) +
ggsci::scale_color_uchicago() +
ggplot2::theme(legend.position="right", plot.title = element_text(size=12)) +
ggplot2::labs(shape = "Countries", color = "Countries", caption="Source: Warin (2020) & Social Progress Index.")
}
} else{
stop("invalid arguments")
}
}
aa <- EpiBibR::epibibr_data()
pkgdown::build_site()
test <- EpiBibR::epibibr_data()
pkgdown::build_site()
aa <- EpiBibR::epibibr_data()
pkgdown::build_site()
aa <-EpiBibR::epibib_data()
knitr::opts_chunk$set(echo = TRUE)
aa <- EpiBibR::epibibr_data()
pkgdown::build_site()
EpiBibR::epibibr_data()
aa <- EpiBibR::epibibr_data()
pkgdown::build_site()
aa <- EpiBibR::epibibr_data()
aa <- EpiBibR::epibibr_data()
pkgdown::build_site()
aa <-EpiBibR::epibib_data()
aa <- EpiBibR::epibibr_data()
library(EpiBibR)
aa <-epibibr_data()
pkgdown::build_site()
pkgdown::build_site()
pkgdown::build_site()
pkgdown::build_site()
pkgdown::build_site()
pkgdown::build_site()
pkgdown::build_site()
library(EpiBibR)
aa <-EpiBibR::epibibr_data()
pkgdown::build_site()
devtools::check_win_release()
library(EpiBibR)
library(EpiBibR)
url <- paste0("https://warin.ca/datalake/epiBib/EpiBib.Rdata")
path <- file.path(tempdir(), "temp.Rdata")
if (httr::http_error(url)) { # network is down = message (not an error anymore)
message("No Internet connection or the server is in maintenance mode.")
return(NULL)
} else { # network is up = proceed to download via curl
message("EpiBibR: downloading remote dataset.")
with(options(timeout = max(300, getOption("timeout"))),curl::curl_download(url, path))
} # /if - network up or down
curl::curl_download(url, path)
#reading the data
rData <- file.path(paste0(tempdir(), "/temp.Rdata"))
load(rData)
#reading the data
rData <- file.path(paste0(tempdir(), "/temp.Rdata"))
EpiBib_data <-load(rData)
load(rData)
EpiBib_data <-EpiBib_data
library(EpiBibR)
library(EpiBibR)
library(EpiBibR)
pkgdown::build_site()
devtools::submit_cran()
devtools::submit_cran()
EpiBibR::epibibr_data()
aa <- epibibr_data()