Skip to content

Commit

Permalink
Swap examples creds and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TreyBilling committed Dec 18, 2024
1 parent e8bf806 commit 2ea52da
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 78 deletions.
10 changes: 2 additions & 8 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@ knitr::opts_chunk$set(
[![codecov](https://codecov.io/gh/ACLED/acledR/graph/badge.svg?token=TDJodXhEvx)](https://codecov.io/gh/ACLED/acledR)
<!-- badges: end -->

Welcome to ACLED's official R package! This package simplifies access to the data via ACLED's API. It also provides convenient functions for making common ACLED data transformations. See dtacled.github.io/acledR for more information and tutorials on how to use the package.


# Overview
Welcome to acledR! This package provides tools to extract and manipulate data from the [Armed Conflict Location and Event Data Project (ACLED)](https://acleddata.com/). It also provides convenient functions for making common ACLED data transformations. See [dtacled.github.io/acledR](https://dtacled.github.io/acledR) for more information and tutorials on how to use the package.

This package provides tools to extract and manipulate data from the [Armed Conflict Location and Event Data Project (ACLED)](https://acleddata.com/).

To access ACLED data, please register an account at [developer.acleddata.com](developer.acleddata.com).

* You can visit our [guide](https://acleddata.com/acleddatanew//wp-content/uploads/2021/11/ACLED_Access-Guide_October-2020.pdf) on how to easily set up your ACLED account.
* We recommend you to save your ACLED API Key in an R object so you can easily re-use your key.
To access ACLED data, please register an account at [developer.acleddata.com](https://developer.acleddata.com). You can find detailed instructions for setting up your account and retreiving an API key [here](https://acleddata.com/acleddatanew//wp-content/uploads/2021/11/ACLED_Access-Guide_October-2020.pdf).


## Installation
Expand Down
74 changes: 13 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,26 @@

[![R-CMD-check](https://github.com/ACLED/acledR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ACLED/acledR/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/gh/ACLED/acledR/graph/badge.svg?token=TDJodXhEvx)](https://codecov.io/gh/ACLED/acledR)

<!-- badges: end -->

# Overview

This package provides tools to extract and manipulate data from the
[Armed Conflict Location and Event Data Project
(ACLED)](https://acleddata.com/).
Welcome to acledR! This package provides tools to extract and manipulate
data from the [Armed Conflict Location and Event Data Project
(ACLED)](https://acleddata.com/). It also provides convenient functions
for making common ACLED data transformations. See
[dtacled.github.io/acledR](https://dtacled.github.io/acledR) for more
information and tutorials on how to use the package.

To access ACLED data, please register an account at
[developer.acleddata.com](developer.acleddata.com).

- You can visit our
[guide](https://acleddata.com/acleddatanew//wp-content/uploads/2021/11/ACLED_Access-Guide_October-2020.pdf)
on how to easily set up your ACLED account.
- We recommend you to save your ACLED API Key in an R object so you can
easily re-use your key.

## Installation (for private repo)

Since the package repo is currently private, you need to tell R and
Github that you’re a collaborator. To do so, you first create a Github
personal access token (PAT). You can set this to expire after a certain
time (the default) or be permanent. We can initiate this process
internally via:

``` r
# install.packages("usethis") if not installed already
# create personal access token - this should redirect to your github page where you can copy the token
usethis::create_github_token()
```

After you’ve copied the PAT from the browser, return to R and run this,
which will store the PAT locally.

``` r
# paste the token where it says YourPAT
credentials::set_github_pat("YourPAT")
# if you run this, it should print your token; if not we've failed
Sys.getenv("GITHUB_PAT")
```

I recommend also setting the PAT in your `.Rprofile` so it’s stored for
all R sessions (i.e., you don’t have to save the PAT and paste it in
each time you re-install).
[developer.acleddata.com](https://developer.acleddata.com). You can find
detailed instructions for setting up your account and retreiving an API
key
[here](https://acleddata.com/acleddatanew//wp-content/uploads/2021/11/ACLED_Access-Guide_October-2020.pdf).

``` r
# to set your PAT for all R sessions, run
file.edit(file.path("~", ".Rprofile"))
# and then paste credentials::set_github_pat("YourPAT") into the .Rprofile script
# save the file
```
## Installation

Now you can install the package and it will automatically locate your
PAT.
The package will be reviewed and available on CRAN shortly. In the
meantime, you can install the package from Github:

``` r
# install from github
devtools::install_github("ACLED/acledR")
```

## Installation (for public use)

Until the acledR package gets added into the Comprehensive R Archive
Network (CRAN), users can utilize devtools to install the package from
Github. Thankfully, the installation is rather simple. You can install
it through the following code:

``` r
devtools::install_github("ACLED/acledR") ## if you are interested in a particular branch, please add a 'ref' argument.
```
2 changes: 1 addition & 1 deletion tests/testthat/setup-acled_access.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Setup for test acled_access

# Run the function to set up the enviornment credentials
# Run the function to set up the environment credentials
acled_access(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"))
3 changes: 1 addition & 2 deletions tests/testthat/test-acled_access.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# Does it save the credentials in the enviornment? - Missing

test_that("acled_access properly stores the credentials", {
# expect_equal(Sys.getenv("acled_email"),"[email protected]")
expect_equal(Sys.getenv("acled_email"),"[email protected]")
expect_equal(Sys.getenv("acled_email"),"[email protected]")
expect_equal(nchar(Sys.getenv("acled_key")), 20)
})

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-acled_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ test_that("Error when one of two countries are wrong",{

## Test what happens when someone inputs acled_access as TRUE but it includes email and key. ----
test_that("Acled_access is ignored",{
expect_true(grepl("t.billing", log_received_data_check_credential$email[1]))
expect_true(grepl("acledrexamples", log_received_data_check_credential$email[1]))
})

# Test errors from incorrectly input arguments. ----
Expand Down Expand Up @@ -305,7 +305,7 @@ test_that("A warning appears that acled_access is being ignored, and the proper
expect_message(acled_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
acled_access = T, log = T, inter_numeric = TRUE), regexp = "acled_access is TRUE, but email and key are included in the function. Ignoring acled_access.")

expect_true(grepl("t.billing", alog$email[1]))
expect_true(grepl("acledrexamples", alog$email[1]))
})


Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-acled_deletions_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test_that("names of columns are correct - unix", {
## Test that email and key are handled appropiately ----

test_that("Email and key are handled as expected without acled_access",{
expect_true(grepl("t.billing", received_deleted_log$email[1]))}
expect_true(grepl("acledrexamples", received_deleted_log$email[1]))}
)

## Test that acled_access is handled appropiately. ----
Expand All @@ -32,7 +32,7 @@ test_that("Email and Key are handled appropiately",{

some_log <- acled_deletions_api(date_deleted = "1658707200", acled_access = T, log = T)

expect_true(grepl("t.billing", some_log$email[1]))}
expect_true(grepl("acledrexamples", some_log$email[1]))}
)

## Date and unix return the same output ----
Expand Down Expand Up @@ -90,7 +90,7 @@ test_that("A warning appears that acled_access is being ignored, and the proper
expect_message(acled_deletions_api(email = Sys.getenv("EMAIL_ADDRESS_EXAMPLES"), key = Sys.getenv("EXAMPLES_KEY"),
date_deleted = "1658707200",acled_access = T, log = T), regexp = "acled_access is TRUE, but email and key are included in the function. Ignoring acled_access.")

expect_true(grepl("t.billing@acleddata.com", alog$email[1]))
expect_true(grepl("acledrexamples@gmail.com", alog$email[1]))
})


Expand Down
2 changes: 1 addition & 1 deletion vignettes/get_started.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Getting Started"
title: "Get Started"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Get Started}
Expand Down

0 comments on commit 2ea52da

Please sign in to comment.