Skip to content

Commit ff9dbcc

Browse files
committed
✨ Add get_unlikely_summary()
1 parent 7faa197 commit ff9dbcc

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export(distance_matrix)
66
export(edge_distribution)
77
export(get_cluster)
88
export(get_total)
9+
export(get_unlikely_summary)
910
export(import_observations)
1011
export(simulate_observations)
1112
export(unlikely_edge_distribution)

R/get_unlikely.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#' Get an overview of the unlikely reasons for each survey and region
2+
#' @inheritParams import_observations
3+
#' @export
4+
#' @importFrom assertthat assert_that
5+
#' @importFrom RSQLite dbGetQuery
6+
get_unlikely_summary <- function(conn = conn) {
7+
assert_that(inherits(conn, "SQLiteConnection"))
8+
"WITH cte AS (
9+
SELECT survey, region, COUNT(id) n
10+
FROM observation
11+
WHERE region IS NOT NULL
12+
GROUP BY survey, region
13+
),
14+
cte_survey AS (
15+
SELECT survey, region FROM cte GROUP BY survey HAVING n = MAX(n)
16+
)
17+
SELECT c.region, c.survey, u.reason
18+
FROM cte_survey AS c
19+
INNER JOIN unlikely AS u ON c.survey = u.survey
20+
ORDER BY c.region, c.survey" |>
21+
dbGetQuery(conn = conn)
22+
}

man/get_unlikely_summary.Rd

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)