Skip to content

Commit

Permalink
deprecate the sas_session_ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkliming committed Sep 21, 2023
1 parent 68f06b8 commit d58891f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 24 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export(get_sas_cfg)
export(get_sas_session)
export(install_saspy)
export(run_sas)
export(sas_session_ssh)
export(sas_session)
export(sascfg)
export(sd2df)
import(checkmate)
Expand Down
26 changes: 19 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ validate_sascfg <- function(sascfg) {
#' @export
get_sas_session <- function() {
if (is.null(.sasr_env$.sas_session)) {
.sasr_env$.sas_session <- sas_session_ssh(sascfg = get_sas_cfg())
.sasr_env$.sas_session <- sas_session(sascfg = get_sas_cfg())
}
if (is.null(.sasr_env$.sas_session)) {
stop(
Expand All @@ -109,28 +109,40 @@ get_sas_session <- function() {
" accordingly.\n",
"You can also set the default sas cofiguration file using `options(sascfg = )` ",
"to allow other files to be used, ",
"or use `sas_session_ssh(sascfg =)` to choose the configuration file manually.\n"
"or use `sas_session(sascfg =)` to choose the configuration file manually.\n"
)
}
return(.sasr_env$.sas_session)
}

#' Create SAS ssh Session Based on Configuration File
#' Create SAS Session Based on Configuration File
#'
#' @description `r lifecycle::badge("experimental")`
#' Create a SAS ssh session.
#' Create a SAS session.
#'
#' @param sascfg (`character`)\cr SAS session configuration.
#'
#' @return SAS session.
#' @export
sas_session_ssh <- function(sascfg = get_sas_cfg()) {
sas_session <- function(sascfg = get_sas_cfg()) {
validate_sascfg(sascfg)
sas <- saspy$SASsession(cfgfile = sascfg)
.sasr_env$.sas_session <- sas
session <- saspy$SASsession(cfgfile = sascfg)
.sasr_env$.sas_session <- session
return(sas)
}

#' Create SAS Session Based on Configuration File
#' @inherit sas_session
#' @description `r lifecycle::badge("deprecated")`
sas_session_ssh <- function(...) {
lifecycle::deprecate_warn(
when = "0.1.3",
what = "sas_session_ssh()",
details = "Please use `sas_session` instead"
)
sas_session(...)
}

#' Obtain the SAS Configuration File
#'
#' @description `r lifecycle::badge("experimental")`
Expand Down
18 changes: 18 additions & 0 deletions man/sas_session.Rd

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

10 changes: 3 additions & 7 deletions man/sas_session_ssh.Rd

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

14 changes: 7 additions & 7 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,26 @@ test_that("install_saspy works", {
test_that("get_sas_session works", {
skip_if_not_installed("mockery")
.sasr_env$.sas_session <- NULL
mockery::stub(get_sas_session, "sas_session_ssh", function(...) TRUE)
mockery::stub(get_sas_session, "sas_session", function(...) TRUE)
expect_true(
get_sas_session()
)
.sasr_env$.sas_session <- NULL
mockery::stub(get_sas_session, "sas_session_ssh", function(...) NULL)
mockery::stub(get_sas_session, "sas_session", function(...) NULL)
expect_error(
get_sas_session(),
"SAS session not established"
)
.sasr_env$.sas_session <- NULL
})

# sas_session_ssh ----
# sas_session ----

test_that("sas_session_ssh works", {
test_that("sas_session works", {
skip_if_not_installed("mockery")
mockery::stub(sas_session_ssh, "saspy$SASsession", function(...) TRUE)
mockery::stub(sas_session_ssh, "validate_sascfg", function(...) TRUE)
expect_true(sas_session_ssh("test"))
mockery::stub(sas_session, "saspy$SASsession", function(...) TRUE)
mockery::stub(sas_session, "validate_sascfg", function(...) TRUE)
expect_true(sas_session("test"))
})

# get_sas_cfg ----
Expand Down
4 changes: 2 additions & 2 deletions vignettes/introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ To use `sasr`, you need to follow these steps
1. The session will be created if there is no session available stored in `.sasr_env$.sas_session`
1. If `.sasr_env$.sas_session` is created, this session will be used by default.
1. Do not create any variable called `.sas_session` in environment `sasr:::.sasr_env`
1. To create the session manually, you can call `sas_session_ssh()`
1. To create the session manually, you can call `sas_session()`
1. `SAS_session` have one argument `sascfg`, pointing to the SAS session configuration file.
1. To use multiple sessions, you need to store the session `your_session <- sas_session_ssh(sascfg)`
1. To use multiple sessions, you need to store the session `your_session <- sas_session(sascfg)`
1. Transfer the datasets from R to SAS using `df2sd`
1. Tunneling must be enabled to transfer datasets.
1. The variable names of the datasets should not contain dots otherwise SAS may not recognize.
Expand Down

0 comments on commit d58891f

Please sign in to comment.