FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
open_data/charities/pre-processing.R at master · traffordDataLab/open_data · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
traffordDataLab
/
open_data
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
3
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
open_data
/
charities
/
pre-processing.R
Copy path
More file actions
More file actions
Latest commit
History
History
History
79 lines (67 loc) · 3.98 KB
Breadcrumbs
open_data
/
charities
/
pre-processing.R
Copy path
File metadata and controls
79 lines (67 loc) · 3.98 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
Charity Commission - register of charities
#
https://register-of-charities.charitycommission.gov.uk/register/full-register-download
#
2021-05-27. ***NOTE: service is currently in BETA ***
#
Obtain a list of all currently registered charities operating within Trafford
#
Data is split over multiple tables which need joining, available as TSV and JSON
#
Data definitions for all the tables can be found at:
#
https://register-of-charities.charitycommission.gov.uk/documents/34602/422354/Data+Definition.docx/f0a342ce-ef45-1401-ee75-26225f6f0d4f?t=1617010186385
library(
tidyverse
); library(
jsonlite
); library(
lubridate
)
#
Main dataset: "charity" - all recorded charities whether currently registered or not
url
<-
"
https://ccewuksprdoneregsadata1.blob.core.windows.net/data/json/publicextract.charity.zip
"
#
Download, extract and load in the data
download.file(
url
,
destfile
=
"
publicextract.charity.zip
"
)
unzip(
"
publicextract.charity.zip
"
,
exdir
=
"
.
"
)
all_charities
<-
fromJSON(
"
publicextract.charity.json
"
,
flatten
=
TRUE
)
#
Tidy-up removing the files we no longer need
file.remove(
"
publicextract.charity.zip
"
)
file.remove(
"
publicextract.charity.json
"
)
#
Get the main charities only, i.e. ignore linked charities which share the same number, and tidy the variables
#
This dataset includes both currently registered charities and those that have been removed
#
All subsequent tables for matching to this main dataset contain all registered and removed charities, so we'll filter for only registered later
main_charities
<-
all_charities
%
>
%
filter(
linked_charity_number
==
0
) %
>
%
#
concatenate the address fields into one for easier representation, but keep the postcode separate
unite(
charity_contact_address
,
charity_contact_address1
,
charity_contact_address2
,
charity_contact_address3
,
charity_contact_address4
,
charity_contact_address5
,
remove
=
FALSE
,
sep
=
"
#
"
) %
>
%
mutate(
charity_contact_address
=
str_replace_all(
charity_contact_address
,
"
#NA
"
,
"
"
)) %
>
%
mutate(
charity_contact_address
=
str_replace_all(
charity_contact_address
,
"
#
"
,
"
,
"
)) %
>
%
mutate(
charity_contact_address
=
str_to_title(
charity_contact_address
,
locale
=
"
en
"
)) %
>
%
mutate(
date_of_registration
=
ymd(as.Date(
date_of_registration
))) %
>
%
select(
registered_charity_number
,
charity_company_registration_number
,
charity_registration_status
,
charity_name
,
charity_type
,
charity_activities
,
date_of_registration
,
charity_contact_address
,
charity_contact_postcode
,
charity_contact_phone
,
charity_contact_email
,
charity_contact_web
)
#
Area of operation - where the charities operate:
url
<-
"
https://ccewuksprdoneregsadata1.blob.core.windows.net/data/json/publicextract.charity_area_of_operation.zip
"
#
Download, extract and load in the data
download.file(
url
,
destfile
=
"
publicextract.charity_area_of_operation.zip
"
)
unzip(
"
publicextract.charity_area_of_operation.zip
"
,
exdir
=
"
.
"
)
areas_of_operation
<-
fromJSON(
"
publicextract.charity_area_of_operation.json
"
,
flatten
=
TRUE
)
#
Tidy-up removing the files we no longer need
file.remove(
"
publicextract.charity_area_of_operation.zip
"
)
file.remove(
"
publicextract.charity_area_of_operation.json
"
)
#
Join the 2 datasets to get just those registered charities that are operating within Trafford
charities_operating_in_trafford
<-
areas_of_operation
%
>
%
#
Just keep those charities who declare that they operate in Trafford
filter(
geographic_area_description
==
"
Trafford
"
) %
>
%
#
Keep the charity number for the join but none of the other variables are needed
select(
registered_charity_number
) %
>
%
left_join(
.
,
main_charities
,
by
=
"
registered_charity_number
"
) %
>
%
#
Keep only those charities that are currently registered (i.e. they haven't been removed)
filter(
charity_registration_status
==
"
Registered
"
) %
>
%
select(
-
charity_registration_status
)
#
Create the CSV output dataset
write_csv(
charities_operating_in_trafford
,
"
charities_operating_in_trafford.csv
"
)
Back
|
FazBrowse Home
|
New Git URL