Skip to content

Commit b73f2c3

Browse files
author
Dominique Quatravaux
committed
[refactor] Move the stopifnot checks into tibble definitions
1 parent df01edd commit b73f2c3

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

confluence.R

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ classful_props_tibble <- function(objects_nodeset) {
9797
select(-row)
9898
}
9999

100+
content_properties <- {
101+
ns <- entities_xml %>% xml_find_all('//object[@class="ContentProperty"]')
102+
tibble(property_id = ns %>% confluence_id) %>%
103+
mutate(ns %>% props_tibble) %>%
104+
mutate(ns %>% classful_props_tibble)
105+
}
106+
100107
## Again, stuff like
101108
##
102109
## object_pages <- entities %>%
@@ -109,7 +116,8 @@ classful_props_tibble <- function(objects_nodeset) {
109116

110117
page_versions <- {
111118
ns <- entities_xml %>% xml_find_all('//object[@class="Page"]')
112-
tibble(content_id = ns %>% confluence_id) %>%
119+
page_versions <-
120+
tibble(content_id = ns %>% confluence_id) %>%
113121
mutate(ns %>% props_tibble) %>%
114122
mutate(ns %>% classful_props_tibble) %>%
115123
mutate(ns %>%
@@ -120,35 +128,29 @@ page_versions <- {
120128
flatten = FALSE) %>%
121129
tibble(ids = .) %>% rowwise %>%
122130
transmute(content_property_ids = xml_text(ids) %>% list))
131+
## page_versions$content_property_ids (as a “multivalued foreign key”)
132+
## ought to contain the same information as
133+
## content_properties[c("content.Page", "property_id")]:
134+
stopifnot({
135+
relation1 <-
136+
page_versions %>%
137+
transmute(content_id, property_id = content_property_ids) %>%
138+
unnest_longer(property_id)
139+
relation2 <-
140+
content_properties %>%
141+
filter(! is.na(content.Page)) %>%
142+
transmute(content_id = content.Page, property_id)
143+
by <- join_by(content_id, property_id)
144+
anti_join(relation1, relation2, by = by) %>% nrow == 0 &&
145+
anti_join(relation2, relation1, by = by) %>% nrow == 0
146+
})
147+
page_versions
123148
}
124149

125-
content_properties <- {
126-
ns <- entities_xml %>% xml_find_all('//object[@class="ContentProperty"]')
127-
tibble(property_id = ns %>% confluence_id) %>%
128-
mutate(ns %>% props_tibble) %>%
129-
mutate(ns %>% classful_props_tibble)
130-
}
131-
132-
## page_versions$content_property_ids (as a “multivalued foreign key”)
133-
## ought to contain the same information as
134-
## content_properties[c("content.Page", "property_id")]:
135-
stopifnot({
136-
relation1 <-
137-
page_versions %>%
138-
transmute(content_id, property_id = content_property_ids) %>%
139-
unnest_longer(property_id)
140-
relation2 <-
141-
content_properties %>%
142-
filter(! is.na(content.Page)) %>%
143-
transmute(content_id = content.Page, property_id)
144-
by <- join_by(content_id, property_id)
145-
anti_join(relation1, relation2, by = by) %>% nrow == 0 &&
146-
anti_join(relation2, relation1, by = by) %>% nrow == 0
147-
})
148-
149150
bodies <- {
150151
ns <- entities_xml %>% xml_find_all('//object[@class="BodyContent"]')
151-
tibble(body_id = ns %>% confluence_id) %>%
152+
bodies <-
153+
tibble(body_id = ns %>% confluence_id) %>%
152154
mutate(ns %>% props_tibble) %>%
153155
mutate(.keep = "unused",
154156
type = case_when(
@@ -157,20 +159,20 @@ bodies <- {
157159
bodyType == 2 ~ "PageEtc") %>%
158160
as_factor) %>%
159161
mutate(ns %>% classful_props_tibble)
162+
stopifnot(bodies %>%
163+
filter(is.na(type)) %>%
164+
nrow == 0)
165+
stopifnot(bodies %>%
166+
filter(! is.na(content.SpaceDescription)) %>%
167+
filter(type != "SpaceDescription") %>%
168+
nrow == 0)
169+
stopifnot(bodies %>%
170+
filter(! is.na(content.CustomContentEntityObject)) %>%
171+
filter(type != "CustomContentEntityObject") %>%
172+
nrow == 0)
173+
bodies
160174
}
161175

162-
stopifnot(bodies %>%
163-
filter(is.na(type)) %>%
164-
nrow == 0)
165-
stopifnot(bodies %>%
166-
filter(! is.na(content.SpaceDescription)) %>%
167-
filter(type != "SpaceDescription") %>%
168-
nrow == 0)
169-
stopifnot(bodies %>%
170-
filter(! is.na(content.CustomContentEntityObject)) %>%
171-
filter(type != "CustomContentEntityObject") %>%
172-
nrow == 0)
173-
174176
user2content <- {
175177
ns <- entities_xml %>%
176178
xml_find_all('//object[@class="User2ContentRelationEntity"]')

0 commit comments

Comments
 (0)