Skip to content

Commit

Permalink
Merge pull request #15 from rstudio/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
edgararuiz authored Dec 13, 2023
2 parents 87dd173 + 8daed4c commit 34356a3
Show file tree
Hide file tree
Showing 61 changed files with 135 additions and 3,094 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ data.rds
^CRAN-RELEASE$
^LICENSE\.md$
^\.github$
^_pkgdown\.yml$
^docs$
^pkgdown$
48 changes: 48 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.1
with:
clean: false
branch: gh-pages
folder: docs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ rsconnect/
.Rproj.user
local.sqlite
data.rds
docs
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Suggests:
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
URL: https://github.com/rstudio/connections
URL: https://github.com/rstudio/connections, https://rstudio.github.io/connections/
BugReports: https://github.com/rstudio/connections/issues
Config/testthat/edition: 3
Config/Needs/website: tidyverse/tidytemplate
14 changes: 12 additions & 2 deletions R/connection-close.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ connection_close <- function(con, host = "", type = "", leave_open = FALSE) {
}

#' @export
connection_close.connConnection <- function(con, host = "", type = "", leave_open = FALSE) {
connection_close.connConnection <- function(
con,
host = "",
type = "",
leave_open = FALSE
) {
connection_close(
con@con,
host = first_non_empty(host, con@host),
Expand All @@ -30,7 +35,12 @@ connection_close.connConnection <- function(con, host = "", type = "", leave_ope
}

#' @export
connection_close.DBIConnection <- function(con, host = NULL, type = NULL, leave_open = FALSE) {
connection_close.DBIConnection <- function(
con,
host = NULL,
type = NULL,
leave_open = FALSE
) {
if (is.null(host)) host <- as.character(class(con))
if (is.null(type)) type <- as.character(class(con))
rscontract_close(host = host, type = type)
Expand Down
3 changes: 2 additions & 1 deletion R/connection-open.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' Opens a connection
#'
#' @param ... Passes arguments to wrapped connection function
#' @param open_pane Signals for the RStudio Connections pane to open. Defaults to TRUE.
#' @param open_pane Signals for the RStudio Connections pane to open.
#' Defaults to TRUE.
#'
#' @examples
#' library(DBI)
Expand Down
2 changes: 1 addition & 1 deletion R/connection-pin-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ read_pin_conn.conn_table <- function(x) {
con <- dbi_run_code(x$con)
tbl_read <- x$tbl
tbl_read$src$con <- con@con
init_dbplyr <- dbplyr::remote_src(tbl_read)
dbplyr::remote_src(tbl_read)
tbl_read
}
3 changes: 0 additions & 3 deletions R/connection-pin-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,3 @@ write_pin_conn.tbl_conn <- function(x, board, ...) {
)
invisible()
}



42 changes: 32 additions & 10 deletions R/connection-view.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@
#' connection_view(con)
#' connection_close(con)
#' @export
connection_view <- function(con, connection_code = "", host = "", name = "", connection_id = "") {
connection_view <- function(
con,
connection_code = "",
host = "",
name = "",
connection_id = ""
) {
UseMethod("connection_view")
}

#' @export
connection_view.connConnection <- function(con, connection_code = "", host = "", name = "", connection_id = NULL) {
connection_view.connConnection <- function(
con,
connection_code = "",
host = "",
name = "",
connection_id = NULL
) {
connection_view(
con = con@con,
connection_code = connection_code,
Expand All @@ -28,7 +40,13 @@ connection_view.connConnection <- function(con, connection_code = "", host = "",
}

#' @export
connection_view.DBIConnection <- function(con, connection_code = "", host = "", name = "", connection_id = "") {
connection_view.DBIConnection <- function(
con,
connection_code = "",
host = "",
name = "",
connection_id = ""
) {
session <- conn_session_get(connection_id)
if (is.null(session)) {
name <- as.character(class(con))
Expand All @@ -47,15 +65,19 @@ connection_view.DBIConnection <- function(con, connection_code = "", host = "",
name = name,
host = host,
connect_script = connect_code,
disconnect_code = function()
connection_close(con, host = host),
object_list = function(catalog = NULL, schema = NULL, ...)
dbi_list_objects(catalog, schema, sch, name, type, con),
disconnect_code = function() {
connection_close(con, host = host)
},
object_list = function(catalog = NULL, schema = NULL, ...) {
dbi_list_objects(catalog, schema, sch, name, type, con)
},
object_columns = function(catalog = NULL, schema = NULL,
table = NULL, view = NULL, ...)
dbi_list_columns(catalog, schema, table, view, sch, con),
preview_code = function(limit, table, schema, ...)
table = NULL, view = NULL, ...) {
dbi_list_columns(catalog, schema, table, view, sch, con)
},
preview_code = function(limit, table, schema, ...) {
dbi_preview_object(limit, table, schema, sch, con)
}
)
rscontract_open(spec_contract)
}
4 changes: 3 additions & 1 deletion R/dbi-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ top_rows <- function(limit = 10, table, schema, sch, con) {
item_to_table <- function(item) {
t <- lapply(
item,
function(x) data_frame(
function(x) {
data_frame(
name = x$name,
type = x$type
)
}
)
tbls <- NULL
for (j in seq_along(t)) {
Expand Down
3 changes: 1 addition & 2 deletions R/dplyr-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ copy_to.connConnection <- function(dest,
df,
name = deparse(substitute(df)),
overwrite = FALSE,
...
) {
...) {
ct <- copy_to(
dest = dest@con,
df = df,
Expand Down
25 changes: 12 additions & 13 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ output: github_document
<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
if(dir.exists("~/pins")) unlink("~/pins", recursive = TRUE)
if (dir.exists("~/pins")) unlink("~/pins", recursive = TRUE)
knitr::opts_chunk$set(
collapse = TRUE,
Expand All @@ -17,7 +16,7 @@ knitr::opts_chunk$set(
)
add_figure <- function(path, width = 400) {
char_html <- paste0("<img src='", path,"' width ='", width,"px'/><br/>")
char_html <- paste0("<img src='", path, "' width ='", width, "px'/><br/>")
htmltools::HTML(char_html)
}
Expand All @@ -34,10 +33,10 @@ toc <- function() {
seq_along(titles),
function(x) {
pad <- ifelse(substr(only_titles[x], 1, 3) == "###", " - ", " - ")
paste0(pad, "[", titles[x], "](#",links[x], ")")
paste0(pad, "[", titles[x], "](#", links[x], ")")
}
)
toc_full <- paste(toc_list, collapse = "\n")
toc_full <- paste(toc_list, collapse = "\n")
cat(toc_full)
}
```
Expand Down Expand Up @@ -81,15 +80,15 @@ Install the development version from [GitHub](https://github.com/) with:

``` r
# install.packages("remotes")
remotes::install_github("edgararuiz/connections")
remotes::install_github("rstudio/connections")
```
```{r setup, include = FALSE}
library(connections)
library(RSQLite)
library(dplyr)
library(pins)
if(file.exists("local.sqlite")) unlink("local.sqlite")
if (file.exists("local.sqlite")) unlink("local.sqlite")
```

## Functions
Expand Down Expand Up @@ -246,7 +245,7 @@ con <- connection_pin_read(board, "my_conn")
tbl_summary <- con %>%
tbl("mtcars") %>%
group_by(cyl) %>%
summarise(avg_mpg = mean(mpg, na.rm = TRUE))
summarise(avg_mpg = mean(mpg, na.rm = TRUE))
connection_pin_write(board, tbl_summary, name = "cyl_mpg")
Expand Down Expand Up @@ -293,14 +292,14 @@ connection_close(con)
library(connections)
library(RPostgres)
con <- connection_open(
Postgres(),
host = "localhost",
Postgres(),
host = "localhost",
dbname = "datawarehouse",
user = "[user id]",
password = "[password]",
user = "[user id]",
password = "[password]",
bigint = "integer",
port = "5432"
)
)
```

`r add_figure("man/figures/postgres-1.png")`
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Install the development version from [GitHub](https://github.com/) with:

``` r
# install.packages("remotes")
remotes::install_github("edgararuiz/connections")
remotes::install_github("rstudio/connections")
```

## Functions
Expand Down Expand Up @@ -156,7 +156,7 @@ library(pins)
board <- board_folder("~/pins")

connection_pin_write(board, con, name = "my_conn")
#> Creating new version '20231213T213608Z-8d9ce'
#> Creating new version '20231213T222754Z-8d9ce'
#> Writing to pin 'my_conn'
```

Expand Down Expand Up @@ -211,7 +211,7 @@ the top results to the R Console. The `pin` records two things:

``` r
connection_pin_write(board, db_mtcars, name = "avg_mpg")
#> Creating new version '20231213T213608Z-956aa'
#> Creating new version '20231213T222755Z-efdfe'
#> Writing to pin 'avg_mpg'
```

Expand Down Expand Up @@ -247,11 +247,11 @@ con <- connection_pin_read(board, "my_conn")
tbl_summary <- con %>%
tbl("mtcars") %>%
group_by(cyl) %>%
summarise(avg_mpg = mean(mpg, na.rm = TRUE))
summarise(avg_mpg = mean(mpg, na.rm = TRUE))


connection_pin_write(board, tbl_summary, name = "cyl_mpg")
#> Creating new version '20231213T213609Z-30482'
#> Creating new version '20231213T222755Z-93829'
#> Writing to pin 'cyl_mpg'

connection_close(con)
Expand Down Expand Up @@ -302,14 +302,14 @@ connection_close(con)
library(connections)
library(RPostgres)
con <- connection_open(
Postgres(),
host = "localhost",
Postgres(),
host = "localhost",
dbname = "datawarehouse",
user = "[user id]",
password = "[password]",
user = "[user id]",
password = "[password]",
bigint = "integer",
port = "5432"
)
)
```

<img src='man/figures/postgres-1.png' width ='400px'/><br/>
Expand Down
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
url: https://rstudio.github.io/connections/
template:
bootstrap: 5

Loading

0 comments on commit 34356a3

Please sign in to comment.