From ebd7ca0b556d351903b768f91c8ccac8664bc87f Mon Sep 17 00:00:00 2001 From: Scott Came Date: Wed, 4 Apr 2018 09:41:05 -0700 Subject: [PATCH] Make dwapi dependency explicit (#33) * Make dwapi package dependency explicit (Issue #31) * Restore prior .onAttach() behavior --- DESCRIPTION | 2 +- R/zzz.R | 28 ++++++++++++++++++---------- data.world-r.Rproj | 3 +++ man/is_attached.Rd | 12 ++++++++++++ man/set_dw_config.Rd | 12 ------------ 5 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 man/is_attached.Rd delete mode 100644 man/set_dw_config.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 2558a71..69a24b5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 , for additional information. -Depends: R (>= 3.3.0), dwapi +Depends: R (>= 3.3.0), dwapi (>= 0.1.3) Imports: httr, ini, diff --git a/R/zzz.R b/R/zzz.R index 131a9be..c97aaa3 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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. @@ -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() } diff --git a/data.world-r.Rproj b/data.world-r.Rproj index 5b6da0d..0ee12cd 100644 --- a/data.world-r.Rproj +++ b/data.world-r.Rproj @@ -5,7 +5,10 @@ SaveWorkspace: No AlwaysSaveHistory: Default EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 Encoding: UTF-8 + RnwWeave: Sweave LaTeX: pdfLaTeX diff --git a/man/is_attached.Rd b/man/is_attached.Rd new file mode 100644 index 0000000..3886e59 --- /dev/null +++ b/man/is_attached.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/zzz.R +\name{is_attached} +\alias{is_attached} +\title{Determine if library is already attached} +\usage{ +is_attached(x) +} +\description{ +Determine if library is already attached +} +\keyword{internal} diff --git a/man/set_dw_config.Rd b/man/set_dw_config.Rd deleted file mode 100644 index 7255f12..0000000 --- a/man/set_dw_config.Rd +++ /dev/null @@ -1,12 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/zzz.R -\name{set_dw_config} -\alias{set_dw_config} -\title{Apply configuration from file or envvars and load dwapi} -\usage{ -set_dw_config() -} -\description{ -Apply configuration from file or envvars and load dwapi -} -\keyword{internal}