-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathREADME.Rmd
More file actions
128 lines (97 loc) · 3.88 KB
/
README.Rmd
File metadata and controls
128 lines (97 loc) · 3.88 KB
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
fig.path = "man/figures/README-",
out.width = "100%",
comment = ""
)
```
# naijR <img src="man/figures/logo.png" width=120px align="right" />
An R package on Nigeria and for Nigeria
<!-- badges: start -->
[](https://cran.r-project.org/package=naijR)
[](https://app.codecov.io/gh/BroVic/naijR?branch=master)
[](https://github.com/ropensci/naijR/actions)
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://github.com/ropensci/software-review/issues/600)
<!-- badges: end -->
The goal of **naijR** is to make it easier for R users to work with data related to Nigeria.
## Usage
### Some simple operations
#### Maps
One of the useful aspects of this package is enabling users to plot country and sub-national geo-spatial maps. Currently, only vector-type graphics are supported. To find out more, read the vignette--accessible from within R as follows:
```{r vignette, eval=FALSE}
vignette('nigeria-maps', 'naijR')
```
### Administrative Regions
#### States
To create a list of all the States of the Nigerian Federation, simply call `states()`.
```{r admin, results='as-is'}
library(naijR, quietly = TRUE)
ss <- states()
head(ss)
cat(sprintf("\n...but Nigeria has %i States.", length(ss)))
```
States from a given geo-political zone can also be selected:
```{r states}
states(gpz = "ne") # i.e. North-East
```
For other capabilities of this function, see `?states()`.
#### Local Government Areas
This is a basic example that shows how to very quickly fetch the names of Local Government Areas within a given State:
```{r states-example}
lgas("Imo")
```
To list all the LGAs in Nigeria, call the same function without any parameters:
```{r lgas}
n <- length(lgas())
sprintf("Nigeria has a total of %i Local Government Areas", n)
```
Want to create a function to check how many LGAs a particular State has?
```{r lgas-func}
how_many_lgas <- function(state) {
n <- length(lgas(state))
cat(state, "State has", n, "LGAs\n")
}
how_many_lgas("Sokoto")
```
### Working with phone numbers
It is common to come across datasets where phone numbers are wrongly entered or misinterpreted by software like MS Excel. The function `fix_mobile()` helps with this.
```{r mobile}
fix_mobile("8032000000")
```
The function works on vectors; thus an entire column of a table with phone numbers can be quickly processed. Illegible or irreparable numbers are turned into missing values, e.g.
```{r mobile-vectorized-1}
(dat <- data.frame(
serialno = 1:8,
phone = c(
"123456789",
"0123456789",
"8000000001",
"9012345678",
"07098765432",
"08123456789",
"09064321987",
"O8055577889"
)
))
```
```{r mobile-vectorized-2}
fix_mobile(dat$phone)
```
## Installation
To download and install the current stable version of this package from CRAN:
```{r cran-install, eval=FALSE}
install.packages("naijR")
```
The development version can be obtained from [GitHub](https://github.com/ropensci/naijR) with:
``` {r dev-install, eval = FALSE}
# install.packages("pak") # if necessary
pak::pkg_install("ropensci/naijR")
```
Please note that this package is released with a [Contributor
Code of Conduct](https://ropensci.org/code-of-conduct/). By contributing to this project, you agree to abide by its terms.