-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEXAMPLE_CODE
187 lines (156 loc) · 9.31 KB
/
EXAMPLE_CODE
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
###################################################################################################
###################################################################################################
# Install accessibletablesR from GitHub
devtools::install_github("minifiemj/accessibletablesR", build_vignettes = TRUE)
library("accessibletablesR")
# If a firewall prevents install_github from working (a time out message may appear) then ...
# ... install package manually
# On the GitHub repo, go to the green Code icon and choose "Download ZIP". Copy the ZIP folder ...
# ... to a network drive.
# Use devtools::install_local(link to the zipped folder) to install the package
###################################################################################################
###################################################################################################
# Example of how to use accessibletablesR
# Run workbook function first
# Unused optional arguments in this example are subject and category
# fontnm, fontcol, fontsz, fontszst and fontszt can be amended from default settings if desired
accessibletablesR::workbook(
covertab = "Yes", contentstab = "Yes", notestab = "Yes",
definitionstab = "Yes", autonotes = "Yes",
title = "Fuel consumption and aspects of car design and performance for various cars",
creator = "An organisation")
# After workbook function, run the creatingtables function as many times as needed
# Unused optional arguments in this example are extraline4, extraline5, extraline6, tablename ...
# ... and gridlines
# gridlines can be amended from default setting if desired (default setting is to have gridlines)
accessibletablesR::creatingtables(
title = "Fuel consumption and aspects of car design and performance for various cars A",
subtitle = "Cars",
extraline1 = "Link to contents",
extraline2 = "Link to notes",
extraline3 = "Link to definitions",
sheetname = "Table_1", table_data = accessibletablesR::dummydf, headrowsize = 40,
numdatacols = c(2:8,11:13), numdatacolsdp = c(1,0,1,0,2,3,2,0,0,1),
othdatacols = c(9,10), datedatacols = 15, datedatafmt = "dd-mm-yyyy",
datenondatacols = 14, datenondatafmt = "yyyy-mm-dd")
accessibletablesR::creatingtables(
title = "Fuel consumption and aspects of car design and performance for various cars B",
subtitle = "Cars",
extraline1 = "Link to contents",
extraline2 = "Link to notes",
extraline3 = "Link to definitions",
sheetname = "Table_2", table_data = accessibletablesR::dummydf, headrowsize = 40,
numdatacols = c(2:8,11:13), numdatacolsdp = c(1,0,1,0,1,0,1,0,0,0),
othdatacols = c(9,10), columnwidths = "characters", width_adj = 1,
datedatacols = 15, datedatafmt = "mm-dd-yyyy",
datenondatacols = 14, datenondatafmt = "yyyy-dd-mm")
accessibletablesR::creatingtables(
title = "Fuel consumption and aspects of car design and performance for various cars C",
subtitle = "Cars",
extraline1 = "Link to contents",
extraline2 = "Link to notes",
extraline3 = "Link to definitions",
sheetname = "Table_3", table_data = accessibletablesR::dummydf, headrowsize = 40,
numdatacols = c(2:8,11:13), numdatacolsdp = c(1,0,1,0,2,1,2,0,0,3),
othdatacols = c(9,10), datedatacols = 15, datedatafmt = "dd-mm-yyyy",
datenondatacols = 14, datenondatafmt = "yyyy-mm-dd", columnwidths = "specified",
colwid_spec = c(18,18,18,15,17,15,12,17,12,13,23,22,12,12,12))
# To create a contents page, run the contentstable function after running creatingtables as ...
# ... many times as needed
# gridlines can be amended from default setting if desired (default setting is to have gridlines)
accessibletablesR::contentstable()
# To create a note that will be applied to the tables, run the addnote function
accessibletablesR::addnote(notenumber = "note1", notetext = "Whatever you want note1 to be.",
applictabtext = c("Table_1", "Table_2"),
linktext1 = "No additional link", linktext2 = NULL)
accessibletablesR::addnote(notenumber = "note2", notetext = "Whatever you want note2 to be",
applictabtext = "Table_1", linktext1 = "No additional link",
linktext2 = NULL)
accessibletablesR::addnote(notenumber = "note3", notetext = "Whatever you want note3 to be",
applictabtext = "Table_2", linktext1 = "No additional link",
linktext2 = NULL)
accessibletablesR::addnote(notenumber = "note4", notetext = "Google is an internet search engine",
applictabtext = "All", linktext1 = "Google",
linktext2 = "https://www.ons.google.co.uk")
# To create a notes page, run the notestab function
# It is recommended to run the notestab function after running creatingtables as many times ...
# ... as needed
# gridlines can be amended from default setting if desired (default setting is to have gridlines)
# contentslink can be amended from default setting if desired. The default is to have a link to ...
# ... the contents page, so change contentslink to "No" if no such link is wanted.
accessibletablesR::notestab()
# Below is an example of how to create an extra column on the notes tab
# Multiple extra columns can be added
#extracols_notes <- data.frame() %>%
# dplyr::mutate(col1 = "") %>%
# dplyr::add_row(col1 = "Whatever you want1") %>%
# dplyr::add_row(col1 = "Whatever you want2") %>%
# dplyr::add_row(col1 = "Whatever you want3") %>%
# dplyr::add_row(col1 = "Whatever you want4") %>%
# dplyr::rename("Extra column name" = col1)
#accessibletablesR::notestab(extracols = "Yes")
# To create a definition that is applicable to the tables, run the adddefinition function
accessibletablesR::adddefinition(
term = "Usual resident",
definition = "A usual resident is anyone who, on Census Day, 21 March 2021 was in the UK ....")
# To create a definitions page, run the definitionstab function
# gridlines can be amended from default setting if desired (default setting is to have gridlines)
# contentslink can be amended from default setting if desired. The default is to have a link to ...
# ... the contents page, so change contentslink to "No" if no such link is wanted.
accessibletablesR::definitionstab()
# To create a cover page, run the coverpage function
# The only compulsory argument to populate is title
# reuse is designed for UK government departments, so if user is not a UK government department ...
# ... do not set reuse to "Yes"
# govdept is set to "ONS" as default, so if user is a UK government department other than ONS ...
# ... amend govdept if a section on reuse is wanted
# gridlines can be amended from default setting if desired (default setting is to have gridlines)
accessibletablesR::coverpage(
title = "Fuel consumption and aspects of car design and performance for various cars",
intro = "Some made up data about cars",
about = "The output of an example of how to use accessibletablesR",
source = "R mtcars",
relatedlink = "https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/mtcars)",
relatedtext = "mtcars: Motor trend car road tests",
dop = "26 October 2023",
blank = "There should be no blank cells",
names = "Your name",
email = "yourname@emailprovider.com",
phone = "01111 1111111111111",
reuse = "Yes", govdept = NULL)
# Below is an example of how to include extra fields, additional links and reordering the fields
# The extrafields can be split out in the order argument if required
#accessibletablesR::coverpage(
# title = "Fuel consumption and aspects of car design and performance for various cars",
# intro = "Some made up data about cars",
# about = "The output of an example of how to use accessibletablesR",
# source =
# "[R mtcars](https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/mtcars)",
# relatedlink = "https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/mtcars)",
# relatedtext = "mtcars: Motor trend car road tests",
# dop = "26 October 2023",
# blank = "There should be no blank cells",
# names = "Your name",
# email = "yourname@emailprovider.com",
# phone = "01111 1111111111111",
# reuse = "Yes", govdept = NULL,
# extrafields = c("Extra heading 1", "Extra heading2", "Extra heading3"),
# extrafieldsb = c("Another line", "Another line", "Another line"),
# additlinks = c("https://www.bbc.co.uk", "https://google.co.uk"),
# addittext = c("BBC", "Google"),
# colwid_spec = 85,
# order = c("intro", "about", "source", "relatedlink", "names", "email", "phone",
# "blank", "extrafields", "additlinks", "reuse"))
# To save the Excel workbook, run the savingtables function
# The only compulsory argument to populate is the filepath of where to save the workbook, ...
# ... including the name to be given to the workbook
# The workbook needs to be given a save name as a xlsx file (code is based on the ...
# ... R package openxlsx)
# Consider saving the workbook as an ods file (for accessibility reasons)
# Default setting is to save the xlsx file but not the ods file
# To save only xlsx, keep odsfile = "No"
# To save both ods and xlsx set odsfile = "Yes" and deletexlsx = "No"
# To save only ods, set odsfile = "Yes" and deletexlsx = "Yes"
accessibletablesR::savingtables("D:/mtcarsexample.xlsx")
#accessibletablesR::savingtables("D:/mtcarsexample.xlsx", odsfile = "Yes")
#accessibletablesR::savingtables("D:/mtcarsexample.xlsx", odsfile = "Yes", deletexlsx = "No")