Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Reduce dependencies #52

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: connector
Title: Connect to your data easily
Version: 0.0.3
Version: 0.0.4
Authors@R: c(
person("Cervan", "Girard", , "[email protected]", role = c("aut", "cre")),
person("Aksel", "Thomsen", , "[email protected]", role = "aut"),
Expand All @@ -20,7 +20,6 @@ Imports:
glue,
haven,
jsonlite,
magrittr,
options,
purrr,
R6 (>= 2.4.0),
Expand All @@ -47,6 +46,6 @@ Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE, r6 = TRUE)
RoxygenNote: 7.3.2
Remotes:
Remotes:
NovoNordisk-OpenSource/zephyr,
NovoNordisk-OpenSource/connector.logger
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ S3method(write_ext,txt)
S3method(write_ext,xpt)
S3method(write_ext,yaml)
S3method(write_ext,yml)
export("%>%")
export(connect)
export(connector)
export(connector_dbi)
Expand Down Expand Up @@ -70,6 +69,5 @@ importFrom(cli,cli_code)
importFrom(cli,cli_inform)
importFrom(cli,cli_text)
importFrom(jsonlite,read_json)
importFrom(magrittr,"%>%")
importFrom(options,define_option)
importFrom(rlang,set_names)
30 changes: 28 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
# connector 0.0.4 (2024-12-03)

### Migration:
- Migration to public github

### Features:
- Update of `create_directory_cnt()`
- Added metadata as a parameter in `connect()`
- More comprehensive testing
- Better integration with [whirl](https://github.com/NovoNordisk-OpenSource/whirl) through [connector.logger](https://github.com/NovoNordisk-OpenSource/connector.logger)

### Other:
- Reducing the number of dependencies.
- Better messages

# connector 0.0.3 (2024-09-25)

### Breaking Changes:
- rename function from `*_cnt` to `cnt_`

### Features:
- Nested connectors objects
- Use active bindings
- User guide added


# connector 0.0.2

* Added `connectors` super class
- Added `connectors` super class

# connector 0.0.1

* Initial version
- Initial version
2 changes: 1 addition & 1 deletion R/connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ connect <- function(config = "_connector.yml", metadata = NULL, datasource = NUL
checkmate::assert_logical(logging)

if (!is.list(config)) {
if (tools::file_ext(config) %in% c("yml", "yaml")) {
if (get_file_ext(config) %in% c("yml", "yaml")) {
config <- read_file(config, eval.expr = TRUE)
} else {
config <- read_file(config)
Expand Down
8 changes: 4 additions & 4 deletions R/connector.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ connector <- R6::R6Class(
#' List available content from the connector. See also [list_content_cnt].
#' @return A [character] vector of content names
list_content_cnt = function(...) {
self %>%
self |>
list_content_cnt(...)
},

Expand All @@ -74,23 +74,23 @@ connector <- R6::R6Class(
#' @return
#' R object with the content. For rectangular data a [data.frame].
read_cnt = function(name, ...) {
self %>%
self |>
read_cnt(name, ...)
},

#' @description
#' Write content to the connector.See also [write_cnt].
#' @return `r rd_connector_utils("inv_self")`
write_cnt = function(x, name, ...) {
self %>%
self |>
write_cnt(x, name, ...)
},

#' @description
#' Remove or delete content from the connector. See also [remove_cnt].
#' @return `r rd_connector_utils("inv_self")`
remove_cnt = function(name, ...) {
self %>%
self |>
remove_cnt(name, ...)
}
)
Expand Down
4 changes: 2 additions & 2 deletions R/dbi.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ connector_dbi <- R6::R6Class(
#' See also [disconnect_cnt].
#' @return [invisible] `self`.
disconnect_cnt = function() {
self %>%
self |>
disconnect_cnt()
},

Expand All @@ -79,7 +79,7 @@ connector_dbi <- R6::R6Class(
#' See also [tbl_cnt].
#' @return A [dplyr::tbl] object.
tbl_cnt = function(name, ...) {
self %>%
self |>
tbl_cnt(name, ...)
}
),
Expand Down
12 changes: 6 additions & 6 deletions R/dbi_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' @rdname read_cnt
#' @export
read_cnt.connector_dbi <- function(connector_object, name, ...) {
connector_object$conn %>%
connector_object$conn |>
DBI::dbReadTable(name = name, ...)
}

Expand All @@ -41,7 +41,7 @@ read_cnt.connector_dbi <- function(connector_object, name, ...) {
#' @rdname write_cnt
#' @export
write_cnt.connector_dbi <- function(connector_object, x, name, ...) {
connector_object$conn %>%
connector_object$conn |>
DBI::dbWriteTable(name = name, value = x, ...)
return(invisible(connector_object))
}
Expand All @@ -59,7 +59,7 @@ write_cnt.connector_dbi <- function(connector_object, x, name, ...) {
#' @rdname list_content_cnt
#' @export
list_content_cnt.connector_dbi <- function(connector_object, ...) {
connector_object$conn %>%
connector_object$conn |>
DBI::dbListTables(...)
}

Expand All @@ -81,7 +81,7 @@ list_content_cnt.connector_dbi <- function(connector_object, ...) {
#' @rdname remove_cnt
#' @export
remove_cnt.connector_dbi <- function(connector_object, name, ...) {
connector_object$conn %>%
connector_object$conn |>
DBI::dbRemoveTable(name = name, ...)
return(invisible(connector_object))
}
Expand Down Expand Up @@ -113,7 +113,7 @@ remove_cnt.connector_dbi <- function(connector_object, name, ...) {
#' @rdname tbl_cnt
#' @export
tbl_cnt.connector_dbi <- function(connector_object, name, ...) {
connector_object$conn %>%
connector_object$conn |>
dplyr::tbl(from = name, ...)
}

Expand All @@ -133,6 +133,6 @@ tbl_cnt.connector_dbi <- function(connector_object, name, ...) {
#' @rdname disconnect_cnt
#' @export
disconnect_cnt.connector_dbi <- function(connector_object, ...) {
connector_object$conn %>%
connector_object$conn |>
DBI::dbDisconnect(...)
}
8 changes: 4 additions & 4 deletions R/fs.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ connector_fs <- R6::R6Class(
#' See also [download_cnt].
#' @return [invisible] `file`
download_cnt = function(name, file = basename(name), ...) {
self %>%
self |>
download_cnt(name, file, ...)
},

Expand All @@ -66,7 +66,7 @@ connector_fs <- R6::R6Class(
#' See also [upload_cnt].
#' @return `r rd_connector_utils("inv_self")`
upload_cnt = function(file, name = basename(file), ...) {
self %>%
self |>
upload_cnt(file, name, ...)
},

Expand All @@ -76,7 +76,7 @@ connector_fs <- R6::R6Class(
#' @param name [character] The name of the directory to create
#' @return [connector_fs] object of a newly created directory
create_directory_cnt = function(name, ...) {
self %>%
self |>
create_directory_cnt(name, ...)
},

Expand All @@ -86,7 +86,7 @@ connector_fs <- R6::R6Class(
#' @param name [character] The name of the directory to remove
#' @return `r rd_connector_utils("inv_self")`
remove_directory_cnt = function(name, ...) {
self %>%
self |>
remove_directory_cnt(name, ...)
}
),
Expand Down
2 changes: 1 addition & 1 deletion R/fs_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ write_cnt.connector_fs <- function(connector_object, x, name, ...) {
#' @rdname list_content_cnt
#' @export
list_content_cnt.connector_fs <- function(connector_object, ...) {
connector_object$path %>%
connector_object$path |>
list.files(...)
}

Expand Down
4 changes: 2 additions & 2 deletions R/fs_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @return the result of the reading function
#' @export
read_file <- function(path, ...) {
find_ext <- tools::file_ext(path)
find_ext <- get_file_ext(path)

class(path) <- c(find_ext, class(path))

Expand Down Expand Up @@ -127,4 +127,4 @@ read_ext.yaml <- read_ext.yml
#' @export
read_ext.json <- function(path, ...) {
jsonlite::read_json(path = path, ...)
}
}
2 changes: 1 addition & 1 deletion R/fs_write.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @return `write_file()`: [invisible()] file.
#' @export
write_file <- function(x, file, ...) {
find_ext <- tools::file_ext(file) |>
find_ext <- get_file_ext(file) |>
assert_ext("write_ext")

class(file) <- c(find_ext, class(file))
Expand Down
14 changes: 0 additions & 14 deletions R/utils-pipe.R

This file was deleted.

14 changes: 14 additions & 0 deletions R/utils_fileext.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Getting file extension
get_file_ext <- function(file_paths) {
vapply(
X = file_paths,
FUN = function(file_path) {
file_name <- basename(file_path)
file_parts <- strsplit(file_name, "\\.")[[1]]
file_extension <- ifelse(length(file_parts) == 1, "", utils::tail(file_parts, 1))
return(file_extension)
},
FUN.VALUE = character(1),
USE.NAMES = FALSE
)
}
4 changes: 2 additions & 2 deletions R/utils_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ assert_ext <- function(ext, method) {
#' @importFrom rlang set_names
#' @noRd
error_extension <- function() {
ext_supp <- supported_fs() %>%
ext_supp <- supported_fs() |>
rlang::set_names("*")
c(
"No method found for this extension, please implement your own method
(to see an example run `connector::example_read_ext()`) or use a supported extension",
"i" = "Supported extensions are:",
ext_supp
) %>%
) |>
cli::cli_abort()
}

Expand Down
6 changes: 3 additions & 3 deletions dev/connector_config_yaml.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extract_datasources(yaml_content)
only_one <- extract_connections(yaml_content)[[1]]

## Extract fct
my_backend <- only_one %>%
my_backend <- only_one |>
extract_backends()

#### Create the backend for fs
Expand Down Expand Up @@ -124,8 +124,8 @@ connect$sdtm$read("iris")

## Manipulate a table with the database

connect$sdtm$tbl("iris") %>%
connect$sdtm$tbl("iris") |>
dplyr::filter(Sepal.Length > 5)


```
```
20 changes: 0 additions & 20 deletions man/pipe.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/connect.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Connect datasources to the connections for a yaml file

Code
iris_f %>% dplyr::collect()
dplyr::collect(iris_f)
Output
# A tibble: 118 x 5
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
Expand Down
Loading
Loading