Skip to content

Commit

Permalink
Make dwapi dependency explicit (#33)
Browse files Browse the repository at this point in the history
* Make dwapi package dependency explicit (Issue #31)

* Restore prior .onAttach() behavior
  • Loading branch information
scottcame authored and rflprr committed Apr 4, 2018
1 parent 6cde5e4 commit ebd7ca0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Description: High-level tools for working with 'data.world' data sets. 'data.wor
charting data on the data.world site, you can access data via 'API' endpoints and
integrations. Use this package to access, query and explore data sets, and to
publish your insights. Visit <https://data.world>, for additional information.
Depends: R (>= 3.3.0), dwapi
Depends: R (>= 3.3.0), dwapi (>= 0.1.3)
Imports:
httr,
ini,
Expand Down
28 changes: 18 additions & 10 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"data.world-r
Copyright 2018 data.world, Inc.
Copyright 2017 data.world, Inc.
Licensed under the Apache License, Version 2.0 (the \"License\");
you may not use this file except in compliance with the License.
Expand All @@ -16,37 +16,45 @@ permissions and limitations under the License.
This product includes software developed at data.world, Inc.
https://data.world"

#' Set up default options
#' @keywords internal
.onLoad <- function(...) {

op <- options()
op.dw <-
list(dw.config_path =
file.path(normalizePath("~", winslash = "/"), ".dw", "config"))
file.path(normalizePath("~", winslash = "/"), ".dw", "config"))

toset <- !(names(op.dw) %in% names(op))
if (any(toset))
options(op.dw[toset])

set_dw_config()

invisible()

}

#' Apply configuration from file or envvars and load dwapi
#' @keywords internal
set_dw_config <- function() {
.onAttach <- function(...) {
# Load dwapi as a result of data.world being attached
if (!is_attached("dwapi")) {
lapply(c("dwapi"), library, character.only = TRUE, warn.conflicts = FALSE)
}

profile <- Sys.getenv("DW_PROFILE", unset = NA)
if (is.na(profile)) {
profile <- "DEFAULT"
}

cs <- cfg_saved(profile = profile)
suppressWarnings(set_config(cs))
suppressWarnings(
data.world::set_config(
data.world::cfg_saved(profile = profile)))

set_config(cfg_env())
data.world::set_config(data.world::cfg_env())

invisible()
}

#' Determine if library is already attached
#' @keywords internal
is_attached <- function(x) {
paste0("package:", x) %in% search()
}
3 changes: 3 additions & 0 deletions data.world-r.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

Expand Down
12 changes: 12 additions & 0 deletions man/is_attached.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions man/set_dw_config.Rd

This file was deleted.

0 comments on commit ebd7ca0

Please sign in to comment.