Skip to content

Commit 4abb216

Browse files
committed
fixed #11, #10
1 parent 076920b commit 4abb216

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+636
-16916
lines changed

.github/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.html

.github/workflows/pkgdown.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
release:
8+
types: [published]
9+
workflow_dispatch:
10+
11+
name: pkgdown.yaml
12+
13+
permissions: read-all
14+
15+
jobs:
16+
pkgdown:
17+
runs-on: ubuntu-latest
18+
# Only restrict concurrency for non-PR jobs
19+
concurrency:
20+
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
21+
env:
22+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
23+
permissions:
24+
contents: write
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- uses: r-lib/actions/setup-pandoc@v2
29+
30+
- uses: r-lib/actions/setup-r@v2
31+
with:
32+
use-public-rspm: true
33+
34+
- uses: r-lib/actions/setup-r-dependencies@v2
35+
with:
36+
extra-packages: any::pkgdown, local::.
37+
needs: website
38+
39+
- name: Build site
40+
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
41+
shell: Rscript {0}
42+
43+
- name: Deploy to GitHub pages 🚀
44+
if: github.event_name != 'pull_request'
45+
uses: JamesIves/github-pages-deploy-action@v4.5.0
46+
with:
47+
clean: false
48+
branch: gh-pages
49+
folder: docs

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ README.qmd
99
README.html
1010
/README_files/*
1111
renv.lock
12+
docs

DESCRIPTION

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: contoso
22
Type: Package
3-
Title: The Contoso Dataset
3+
Title: Dataset of the 'Contoso' Company
44
Version: 1.0.0
55
Authors@R: c(
66
person(
@@ -9,27 +9,28 @@ Authors@R: c(
99
role = c("aut", "cre")
1010
)
1111
)
12-
Description: This package provides access to a made-up dataset simulating sales transactions from the fictional "Contoso" company. The dataset includes various related tables that contain essential business and operational data, useful for analyzing sales performance and other business insights. Key tables included in the package are:
12+
Description: A collection of synthetic datasets simulating sales transactions from a fictional company. The dataset includes various related tables that contain essential business and operational data, useful for analyzing sales performance and other business insights. Key tables included in the package are:
1313
- "sales": Contains data on individual sales transactions, including order details, pricing, quantities, and customer information.
1414
- "customer": Stores customer-specific details such as demographics, geographic location, occupation, and birthday.
1515
- "store": Provides information about stores, including location, size, status, and operational dates.
1616
- "orders": Contains details about customer orders, including order and delivery dates, store, and customer data.
17-
- "orderrows": Provides detailed information about each item in an order, including product, quantity, pricing, and cost.
1817
- "product": Contains data on products, including attributes such as product name, category, price, cost, and weight.
19-
- "fx": Foreign exchange data with exchange rates for different currencies used in the sales transactions.
2018
- "date": A time-based table that includes date-related attributes like year, month, quarter, day, and working day indicators.
2119
This dataset is ideal for practicing data analysis, performing time-series analysis, creating reports, or simulating business intelligence scenarios.
2220
License: MIT + file LICENSE
2321
Imports:
2422
DBI,
2523
dplyr,
26-
duckdb
24+
cli,
25+
duckdb (>= 1.4.0)
2726
Suggests:
2827
testthat (>= 3.0.0)
2928
Encoding: UTF-8
3029
LazyData: true
3130
RoxygenNote: 7.3.2
31+
Roxygen: list(markdown = TRUE)
3232
Depends:
3333
R (>= 3.5)
34-
URL: https://usrbinr.github.io/contoso/
34+
URL: https://usrbinr.github.io/contoso/, https://github.com/usrbinr/contoso
3535
Config/testthat/edition: 3
36+
BugReports: https://github.com/usrbinr/contoso/issues

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(create_contoso_duckdb)
4+
export(launch_ui)

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# contoso 1.1.0
2+
* launch_ui function added
3+
* pkgdown instead of altdocs
4+
* new logo
5+
6+
17
# contoso 1.0.0
28

39
* Support for 100M row database now supported

R/database.R

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#' - `store`: Contains information about store locations and attributes.
1515
#' - `fx`: Contains foreign exchange rate data for currency conversion.
1616
#' - `date`: Contains various date-related information, including day, week, month, and year.
17+
#' - `con`: the duckdb connection to your database
1718
#'
1819
#' You can choose to store the database in memory or in a temporary directory. If you choose "temp", the database will be created in a temporary file on disk. If you choose "in_memory", the database will be created entirely in memory and will be discarded after the R session ends.
1920
#'
@@ -54,10 +55,9 @@ create_contoso_duckdb <- function(db_dir= c("in_memory"),size="100K"){
5455

5556
#attach motherduck database
5657

57-
suppressWarnings(DBI::dbExecute(con,"INSTALL motherduck;"))
58-
59-
suppressWarnings(DBI::dbExecute(con,"ATTACH 'md:_share/contoso/5cd50a2d-d482-4160-b260-f10091290db9' as contoso"))
58+
suppressWarnings(DBI::dbExecute(con,"INSTALL motherduck;"))
6059

60+
suppressWarnings(DBI::dbExecute(con,"ATTACH 'md:_share/contoso/5cd50a2d-d482-4160-b260-f10091290db9' as contoso"))
6161

6262
tables_vec <- c("sales","product","customer","store","orders","orderrows","fx","date")
6363

@@ -92,9 +92,76 @@ out <- list(
9292
,date=date_db
9393
,orders=orders_db
9494
,orderrows=orderrows_db
95+
,con=con
9596
)
9697

9798

9899

99100
return(out)
100101
}
102+
103+
104+
105+
106+
107+
#' @title Launch the DuckDB UI in your browser
108+
#'
109+
#' @name launch_ui
110+
#'
111+
#' @description
112+
#' The `launch_ui()` function installs and launches the DuckDB UI extension
113+
#' for an active DuckDB database connection. This allows users to interact
114+
#' with the database via a web-based graphical interface.
115+
#'
116+
#' Your connection from [create_contoso_duckdb()] is returned in the list.
117+
#'
118+
#' @param .con A valid `DBIConnection` object connected to a DuckDB database.
119+
#' The function will check that the connection is valid before proceeding.
120+
#'
121+
#' @details
122+
#' The function performs the following steps:
123+
#'
124+
#' * Checks that the provided DuckDB connection is valid.
125+
#' If the connection is invalid, it aborts with a descriptive error message.
126+
#' * Installs the `ui` extension into the connected DuckDB instance.
127+
#' * Calls the `start_ui()` procedure to launch the DuckDB UI in your browser.
128+
#'
129+
#' This provides a convenient way to explore and manage DuckDB databases
130+
#' interactively without needing to leave the R environment.
131+
#'
132+
#' @return
133+
#' The function is called for its side effects and does not return a value.
134+
#' It launches the DuckDB UI and opens it in your default web browser.
135+
#' @seealso
136+
#' - [create_contoso_duckdb()] for creating example Contoso datasets in DuckDB.
137+
#' - [DBI::dbConnect()] and [DBI::dbDisconnect()] for managing DuckDB connections.
138+
#' - [duckdb::duckdb()] for creating a DuckDB driver instance.
139+
#' @examples
140+
#' \dontrun{
141+
#' # Connect to DuckDB
142+
#' db <- create_contoso_duckdb()
143+
#'
144+
#' # Launch the DuckDB UI
145+
#' launch_ui(db$con)
146+
#'
147+
#' # Clean up
148+
#' DBI::dbDisconnect(db$con, shutdown = TRUE)
149+
#' }
150+
#'
151+
#' @export
152+
launch_ui <- function(.con){
153+
154+
if (!DBI::dbIsValid(db$con)) {
155+
156+
cli::cli_abort("Database connection is invalid, please reconnect before proceeding.")
157+
}
158+
159+
DBI::dbExecute(.con,"install ui;")
160+
161+
DBI::dbExecute(.con,"CALL start_ui()")
162+
163+
}
164+
165+
166+
167+
utils::globalVariables(c("db"))

README.html

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,7 @@
8383

8484

8585

86-
<div class="quarto-figure quarto-figure-center">
87-
<figure class="figure">
88-
<p><img src="man/figures/logo.png" class="img-fluid figure-img"></p>
89-
<figcaption>logo</figcaption>
90-
</figure>
91-
</div>
86+
<p><img src="man/figures/logo.png" class="img-fluid"></p>
9287
<p>Contoso is a synthetic dataset containing sample sales transaction data for the fictional “Contoso” company. It includes various supporting tables for business intelligence, such as customer, store, product, and currency exchange data.</p>
9388
<p>This dataset is perfect for practicing time series analysis, joins, financial modeling, or any business intelligence-related tasks.</p>
9489
<p>It comes with a built-in dataset as well as the ability to create an in-memory database with <a href="https://duckdb.org/">duckdb</a></p>
@@ -164,19 +159,19 @@ <h3 class="anchored" data-anchor-id="dataset-overview">Dataset overview</h3>
164159

165160
<script>
166161
// Create table-specific functions using external factory
167-
const tableFns_1w4a7siixuaimqxdf5pk = TinyTable.createTableFunctions("tinytable_1w4a7siixuaimqxdf5pk");
162+
const tableFns_s48fp1hkow64cexbrs1q = TinyTable.createTableFunctions("tinytable_s48fp1hkow64cexbrs1q");
168163
// tinytable span after
169164
window.addEventListener('load', function () {
170165
var cellsToStyle = [
171166
// tinytable style arrays after
172-
{ positions: [ { i: '5', j: 1 }, { i: '5', j: 2 }, { i: '5', j: 3 }, { i: '5', j: 4 }, { i: '5', j: 5 }, { i: '5', j: 6 }, { i: '5', j: 7 } ], css_id: 'tinytable_css_e8grj3k1xqq4i47rabie',},
173-
{ positions: [ { i: '0', j: 1 }, { i: '0', j: 2 }, { i: '0', j: 3 }, { i: '0', j: 4 }, { i: '0', j: 5 }, { i: '0', j: 6 }, { i: '0', j: 7 } ], css_id: 'tinytable_css_it5dtezjsr54gafiy0q1',},
167+
{ positions: [ { i: '5', j: 1 }, { i: '5', j: 2 }, { i: '5', j: 3 }, { i: '5', j: 4 }, { i: '5', j: 5 }, { i: '5', j: 6 }, { i: '5', j: 7 } ], css_id: 'tinytable_css_xxcjrk94u3k2g5licaln',},
168+
{ positions: [ { i: '0', j: 1 }, { i: '0', j: 2 }, { i: '0', j: 3 }, { i: '0', j: 4 }, { i: '0', j: 5 }, { i: '0', j: 6 }, { i: '0', j: 7 } ], css_id: 'tinytable_css_1cmshl3bg9nwi6pk66ze',},
174169
];
175170

176171
// Loop over the arrays to style the cells
177172
cellsToStyle.forEach(function (group) {
178173
group.positions.forEach(function (cell) {
179-
tableFns_1w4a7siixuaimqxdf5pk.styleCell(cell.i, cell.j, group.css_id);
174+
tableFns_s48fp1hkow64cexbrs1q.styleCell(cell.i, cell.j, group.css_id);
180175
});
181176
});
182177
});
@@ -185,11 +180,11 @@ <h3 class="anchored" data-anchor-id="dataset-overview">Dataset overview</h3>
185180
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/vincentarelbundock/tinytable@main/inst/tinytable.css">
186181
<style>
187182
/* tinytable css entries after */
188-
#tinytable_1w4a7siixuaimqxdf5pk td.tinytable_css_e8grj3k1xqq4i47rabie, #tinytable_1w4a7siixuaimqxdf5pk th.tinytable_css_e8grj3k1xqq4i47rabie { position: relative; --border-bottom: 1; --border-left: 0; --border-right: 0; --border-top: 0; --line-color-bottom: black; --line-color-left: black; --line-color-right: black; --line-color-top: black; --line-width-bottom: 0.1em; --line-width-left: 0.1em; --line-width-right: 0.1em; --line-width-top: 0.1em; --trim-bottom-left: 0%; --trim-bottom-right: 0%; --trim-left-bottom: 0%; --trim-left-top: 0%; --trim-right-bottom: 0%; --trim-right-top: 0%; --trim-top-left: 0%; --trim-top-right: 0%; }
189-
#tinytable_1w4a7siixuaimqxdf5pk td.tinytable_css_it5dtezjsr54gafiy0q1, #tinytable_1w4a7siixuaimqxdf5pk th.tinytable_css_it5dtezjsr54gafiy0q1 { position: relative; --border-bottom: 1; --border-left: 0; --border-right: 0; --border-top: 1; --line-color-bottom: black; --line-color-left: black; --line-color-right: black; --line-color-top: black; --line-width-bottom: 0.05em; --line-width-left: 0.1em; --line-width-right: 0.1em; --line-width-top: 0.1em; --trim-bottom-left: 0%; --trim-bottom-right: 0%; --trim-left-bottom: 0%; --trim-left-top: 0%; --trim-right-bottom: 0%; --trim-right-top: 0%; --trim-top-left: 0%; --trim-top-right: 0%; }
183+
#tinytable_s48fp1hkow64cexbrs1q td.tinytable_css_xxcjrk94u3k2g5licaln, #tinytable_s48fp1hkow64cexbrs1q th.tinytable_css_xxcjrk94u3k2g5licaln { position: relative; --border-bottom: 1; --border-left: 0; --border-right: 0; --border-top: 0; --line-color-bottom: black; --line-color-left: black; --line-color-right: black; --line-color-top: black; --line-width-bottom: 0.1em; --line-width-left: 0.1em; --line-width-right: 0.1em; --line-width-top: 0.1em; --trim-bottom-left: 0%; --trim-bottom-right: 0%; --trim-left-bottom: 0%; --trim-left-top: 0%; --trim-right-bottom: 0%; --trim-right-top: 0%; --trim-top-left: 0%; --trim-top-right: 0%; }
184+
#tinytable_s48fp1hkow64cexbrs1q td.tinytable_css_1cmshl3bg9nwi6pk66ze, #tinytable_s48fp1hkow64cexbrs1q th.tinytable_css_1cmshl3bg9nwi6pk66ze { position: relative; --border-bottom: 1; --border-left: 0; --border-right: 0; --border-top: 1; --line-color-bottom: black; --line-color-left: black; --line-color-right: black; --line-color-top: black; --line-width-bottom: 0.05em; --line-width-left: 0.1em; --line-width-right: 0.1em; --line-width-top: 0.1em; --trim-bottom-left: 0%; --trim-bottom-right: 0%; --trim-left-bottom: 0%; --trim-left-top: 0%; --trim-right-bottom: 0%; --trim-right-top: 0%; --trim-top-left: 0%; --trim-top-right: 0%; }
190185
</style>
191186
<div class="container">
192-
<table class="tinytable" id="tinytable_1w4a7siixuaimqxdf5pk" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
187+
<table class="tinytable" id="tinytable_s48fp1hkow64cexbrs1q" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
193188

194189
<thead>
195190
<tr>

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
## Contoso
3+
![](man/figures/logo.png)
44

55
Contoso is a synthetic dataset containing sample sales transaction data
66
for the fictional “Contoso” company. It includes various supporting
@@ -45,8 +45,6 @@ Built into the package is the 10K row version of the dataset.
4545
Using `view()`, you can see the columns’ label using the
4646
[labelled](https://larmarange.github.io/labelled/index.html) package.
4747

48-
> [!NOTE]
49-
>
5048
> Inspiration to using
5149
> [labelled](https://larmarange.github.io/labelled/index.html) comes
5250
> from [Crystal Lewis](https://cghlewis.com/blog/dict_clean/) excellent

README.qmd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ Built into the package is the 10K row version of the dataset.
3737

3838
Using `view()`, you can see the columns' label using the [labelled](https://larmarange.github.io/labelled/index.html) package.
3939

40-
::: {.callout-note}
41-
Inspiration to using [labelled](https://larmarange.github.io/labelled/index.html) comes from [Crystal Lewis](https://cghlewis.com/blog/dict_clean/) excellent blog post
42-
:::
40+
41+
> Inspiration to using [labelled](https://larmarange.github.io/labelled/index.html) comes from [Crystal Lewis](https://cghlewis.com/blog/dict_clean/) excellent blog post
4342
4443
If you want a larger dataset, there is also 100K, 1M, 10M and 100M row version which can be created with `create_contoso_duckdb()` function.
4544

0 commit comments

Comments
 (0)