Title: | Use 'SAS', R, and 'quarto' Together |
---|---|
Description: | Use R and 'SAS' within reproducible multilingual 'quarto' documents. Run 'SAS' code blocks interactively, send data back and forth between 'SAS' and R, and render 'SAS' output within quarto documents. 'SAS' connections are established through a combination of 'SASPy' and 'reticulate'. |
Authors: | Ryan Zomorrodi [aut, cre, cph] (ORCID: <https://orcid.org/0009-0003-6417-5985>) |
Maintainer: | Ryan Zomorrodi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.0.9045 |
Built: | 2025-08-18 18:34:58 UTC |
Source: | https://github.com/ropensci/sasquatch |
Adds sascfg_personal.py
and authinfo
files and prefills relevant info
according to a specified template.
configure_saspy(template = c("none", "oda"), overwrite = FALSE)
configure_saspy(template = c("none", "oda"), overwrite = FALSE)
template |
Default template to base configuration files off of. |
overwrite |
Can new configuration files overwrite existing config files (if they exist)? |
Configuration for SAS can vary greatly based on your computer's operating
system and the SAS platform you wish to connect to (see
vignette("configuration")
for more information).
Regardless of your desired configuration, configuration always starts with
the creation of a sascfg_personal.py
file within the SASPy
package
installation. This will look like:
SAS_config_names = ['config_name'] config_name = { }
SAS_config_names
should contain a string list of the variable names
of all configurations. Configurations are specified as dictionaries,
and configuration parameters depend on the access method.
Additionally, some access methods will require an additional
authentication file (.authinfo
for Linux and Mac, _authinfo
for Windows) stored in the user's home directory, which are
constructed as follows:
config_name user {your username} password {your password}
The "none"
template simply creates a sascfg_personal.py
file within
the SASPy
package installation.
The "oda"
template will set up a configuration for SAS On Demand for
Academics. The sascfg_personal.py
and authinfo
files will be
automatically configured using the information you provide through prompts.
No return value.
## Not run: config_saspy() ## End(Not run)
## Not run: config_saspy() ## End(Not run)
Installs the SASPy
package and its dependencies within a
virtual Python environment.
Behavior was derived from tensorflow::install_tensorflow()
.
install_saspy( method = c("auto", "virtualenv", "conda"), conda = "auto", envname = "r-saspy", extra_packages = NULL, restart_session = TRUE, conda_python_version = NULL, ..., pip_ignore_installed = FALSE, new_env = identical(envname, "r-saspy"), python_version = NULL )
install_saspy( method = c("auto", "virtualenv", "conda"), conda = "auto", envname = "r-saspy", extra_packages = NULL, restart_session = TRUE, conda_python_version = NULL, ..., pip_ignore_installed = FALSE, new_env = identical(envname, "r-saspy"), python_version = NULL )
method |
By default, |
conda |
The path to a conda executable. Use |
envname |
The name, or full path, of the environment in which Python packages are to be installed. |
extra_packages |
Additional packages to install. |
restart_session |
Restart session? |
conda_python_version |
Passed to conda (only applicable if |
... |
other arguments passed to |
pip_ignore_installed |
Should pip ignore installed python packages and reinstall all already installed python packages? |
new_env |
If |
python_version |
Select the Python that will be used to create the virtualenv. Pass a string with
version constraints like |
No return value.
## Not run: install_saspy() ## End(Not run)
## Not run: install_saspy() ## End(Not run)
Starts a SAS session. This is required before doing anything!
sas_connect(cfgname, reconnect = FALSE)
sas_connect(cfgname, reconnect = FALSE)
cfgname |
string; Name of configuration to use from the SAS_config_names
list within in |
reconnect |
logical; Establish a new connection if a connection already exists? |
All configurations are specified within the sascfg_personal.py
file inside
the SASPy
package. For more information about SASPy
configuration, check
out the configuration documentation
or vignette("configuration")
.
No return value.
Other session management functions:
sas_disconnect()
,
sas_get_session()
## Not run: sas_connect(cfgname = "oda") ## End(Not run)
## Not run: sas_connect(cfgname = "oda") ## End(Not run)
Disconnects from the current SAS session.
sas_disconnect()
sas_disconnect()
No return value.
Other session management functions:
sas_connect()
,
sas_get_session()
## Not run: sas_disconnect() ## End(Not run)
## Not run: sas_disconnect() ## End(Not run)
knitr
Produces HTML or latex output for rending within quarto or rmarkdown documents.
sas_engine(options)
sas_engine(options)
options |
Options from |
Will be activated by running library(sasquatch)
knitr
chunk optionssasquatch
's engine implements may of the same options as the R engine in
knitr
, but not all.
eval
(Default: TRUE
): Evaluate the code chunk (if false, just echos the
code into the output)
echo
(Default: TRUE
): Include the source code in output
output
(Default: TRUE
): Include the results of executing the code in
the output (TRUE
or FALSE
).
include
(Default: TRUE
): Include any output (code or results).
capture
(Only within HTML; Default: "both"
): If "both"
, tabpanel with output and log
included. If "listing"
, only output is included. If "log"
only log is included.
knitr
engine output.
# The below function is run internally within `sasquatch` on startup knitr::knit_engines$set(sas = sas_engine)
# The below function is run internally within `sasquatch` on startup knitr::knit_engines$set(sas = sas_engine)
Copies a file on the remote SAS server. Is analogous to
file.copy()
, but for the remote SAS server.
sas_file_copy(from_path, to_path)
sas_file_copy(from_path, to_path)
from_path |
string; Path of file on remote SAS server to be copied. |
to_path |
string; Path of file on remote SAS server to copy to. |
logical
; value indicating if the operation succeeded.
Other file management functions:
sas_file_download()
,
sas_file_exists()
,
sas_file_remove()
,
sas_file_upload()
,
sas_list()
## Not run: # connect to SAS sas_connect() # create a file and upload it to SAS cat("PROC MEANS DATA = sashelp.cars;RUN;", file = "script.sas") sas_file_upload(local_path = "script.sas", sas_path = "~/script.sas") # copy file on SAS sas_file_copy("~/script.sas", "~/script_copy.sas") ## End(Not run)
## Not run: # connect to SAS sas_connect() # create a file and upload it to SAS cat("PROC MEANS DATA = sashelp.cars;RUN;", file = "script.sas") sas_file_upload(local_path = "script.sas", sas_path = "~/script.sas") # copy file on SAS sas_file_copy("~/script.sas", "~/script_copy.sas") ## End(Not run)
Downloads a file to the remote SAS server.
sas_file_download(sas_path, local_path)
sas_file_download(sas_path, local_path)
sas_path |
string; Path of file on remote SAS server to be download |
local_path |
string; Path to upload SAS file to on local machine. |
logical
; value indicating if the operation succeeded.
Other file management functions:
sas_file_copy()
,
sas_file_exists()
,
sas_file_remove()
,
sas_file_upload()
,
sas_list()
## Not run: # connect to SAS sas_connect() # create a file and upload it to SAS cat("PROC MEANS DATA = sashelp.cars;RUN;", file = "script.sas") sas_file_upload(local_path = "script.sas", sas_path = "~/script.sas") # download file from SAS sas_file_download(sas_path = "~/script.sas", local_path = "script.sas") ## End(Not run)
## Not run: # connect to SAS sas_connect() # create a file and upload it to SAS cat("PROC MEANS DATA = sashelp.cars;RUN;", file = "script.sas") sas_file_upload(local_path = "script.sas", sas_path = "~/script.sas") # download file from SAS sas_file_download(sas_path = "~/script.sas", local_path = "script.sas") ## End(Not run)
Checks if a file exists on the remote SAS server. Is analogous to
file.exists()
, but for the remote SAS server.
sas_file_exists(path)
sas_file_exists(path)
path |
string; Path of file on remote SAS server. |
logical
; value indicating if the operation succeeded.
Other file management functions:
sas_file_copy()
,
sas_file_download()
,
sas_file_remove()
,
sas_file_upload()
,
sas_list()
## Not run: # connect to SAS sas_connect() # create a file and upload it to SAS cat("PROC MEANS DATA = sashelp.cars;RUN;", file = "script.sas") sas_file_upload(local_path = "script.sas", sas_path = "~/script.sas") # check if file exists on SAS sas_file_exists("~/script.sas") ## End(Not run)
## Not run: # connect to SAS sas_connect() # create a file and upload it to SAS cat("PROC MEANS DATA = sashelp.cars;RUN;", file = "script.sas") sas_file_upload(local_path = "script.sas", sas_path = "~/script.sas") # check if file exists on SAS sas_file_exists("~/script.sas") ## End(Not run)
Deletes a file or directory from the remote SAS server. Is analogous to
file.remove()
, but for the remote SAS server.
sas_file_remove(path)
sas_file_remove(path)
path |
string; Path of file on remote SAS server to be deleted. |
logical
; value indicating if the operation succeeded.
Other file management functions:
sas_file_copy()
,
sas_file_download()
,
sas_file_exists()
,
sas_file_upload()
,
sas_list()
## Not run: # connect to SAS sas_connect() # create a file and upload it to SAS cat("PROC MEANS DATA = sashelp.cars;RUN;", file = "script.sas") sas_file_upload(local_path = "script.sas", sas_path = "~/script.sas") # remove file from SAS sas_file_remove(sas_path = "~/script.sas") ## End(Not run)
## Not run: # connect to SAS sas_connect() # create a file and upload it to SAS cat("PROC MEANS DATA = sashelp.cars;RUN;", file = "script.sas") sas_file_upload(local_path = "script.sas", sas_path = "~/script.sas") # remove file from SAS sas_file_remove(sas_path = "~/script.sas") ## End(Not run)
Uploads a file to the remote SAS server.
sas_file_upload(local_path, sas_path)
sas_file_upload(local_path, sas_path)
local_path |
string; Path of file on local machine to be uploaded. |
sas_path |
string; Path to upload local file to on the remote SAS server. |
logical
; value indicating if the operation succeeded.
Other file management functions:
sas_file_copy()
,
sas_file_download()
,
sas_file_exists()
,
sas_file_remove()
,
sas_list()
## Not run: # connect to SAS sas_connect() # create a file to upload cat("PROC MEANS DATA = sashelp.cars;RUN;", file = "script.sas") # upload file sas_file_upload(local_path = "script.sas", sas_path = "~/script.sas") ## End(Not run)
## Not run: # connect to SAS sas_connect() # create a file to upload cat("PROC MEANS DATA = sashelp.cars;RUN;", file = "script.sas") # upload file sas_file_upload(local_path = "script.sas", sas_path = "~/script.sas") ## End(Not run)
Converts R table into a table in the current SAS session. R tables must only have logical, integer, double, factor, character, POSIXct, or Date class columns.
sas_from_r(x, table_name, libref = "WORK")
sas_from_r(x, table_name, libref = "WORK")
x |
|
table_name |
string; Name of table to be created in SAS. |
libref |
string; Name of libref to store SAS table within. |
SAS only has two data types (numeric and character). Data types are converted as follows:
logical -> numeric
integer -> numeric
double -> numeric
factor -> character
character -> character
POSIXct -> numeric (datetime; timezones are lost)
Date -> numeric (date)
data.frame
; x
.
## Not run: sas_connect() sas_from_r(mtcars, "mtcars") ## End(Not run)
## Not run: sas_connect() sas_from_r(mtcars, "mtcars") ## End(Not run)
Returns the current SAS session, which can be used to extend sasquatch
functionality or access the current session within Python.
sas_get_session()
sas_get_session()
sasquatch
functionalitySASPy
has a wealth of functionality, some of which have not all been
implemented within sasquatch
. sas_get_session()
offers a gateway to
unimplemented functionality within the
SASsession class.
When utilizing Python, R, and SAS, start the session within R using
sas_connect()
and utilize reticulate
to pass the
saspy.sasbase.SASsession
object to Python.
saspy.sasbase.SASsession
; Current SAS session.
Other session management functions:
sas_connect()
,
sas_disconnect()
## Not run: sas_connect() sas_get_session() ## End(Not run)
## Not run: sas_connect() sas_get_session() ## End(Not run)
Lists the files or directories of a directory within the remote SAS server.
sas_list(path)
sas_list(path)
path |
string; Path of directory on remote SAS server to list the contents of. |
character
vector; File or directory names.
Other file management functions:
sas_file_copy()
,
sas_file_download()
,
sas_file_exists()
,
sas_file_remove()
,
sas_file_upload()
## Not run: sas_connect() sas_list(".") ## End(Not run)
## Not run: sas_connect() sas_list(".") ## End(Not run)
Execute a SAS file and render html output or save output as html and log.
sas_run_file(input_path, output_path, overwrite = FALSE)
sas_run_file(input_path, output_path, overwrite = FALSE)
input_path |
string; Path of SAS file to run. |
output_path |
optional string; Path to save html output to (log file will be named the same). |
overwrite |
logical; Can output overwrite prior output? |
If output_path
specified, htmlwidget
. Else, no return value.
Other code execution functions:
sas_run_selected()
,
sas_run_string()
## Not run: cat("PROC MEANS DATA = sashelp.cars;\n RUN;", file = "test.sas") sas_connect() sas_run_file("test.sas", "test.html") ## End(Not run)
## Not run: cat("PROC MEANS DATA = sashelp.cars;\n RUN;", file = "test.sas") sas_connect() sas_run_file("test.sas", "test.html") ## End(Not run)
Execute selected SAS code in current session and render html output as SAS
widget. See vignette("overview")
for more information on how to utilize
the addin within RStudio or Positron.
sas_run_selected()
sas_run_selected()
htmlwidget
; HTML5 output.
Other code execution functions:
sas_run_file()
,
sas_run_string()
## Not run: sas_connect() # highlight something in the active editor of RStudio or Positron sas_run_selected() ## End(Not run)
## Not run: sas_connect() # highlight something in the active editor of RStudio or Positron sas_run_selected() ## End(Not run)
Execute SAS code in current session and render html output.
sas_run_string(input)
sas_run_string(input)
input |
string; SAS code to run. |
htmlwidget
; HTML5 output.
Other code execution functions:
sas_run_file()
,
sas_run_selected()
## Not run: sas_connect() sas_run_string("PROC MEANS DATA = sashelp.cars;RUN;") ## End(Not run)
## Not run: sas_connect() sas_run_string("PROC MEANS DATA = sashelp.cars;RUN;") ## End(Not run)
Converts table from current SAS session into a R data.frame
.
sas_to_r(table_name, libref = "WORK")
sas_to_r(table_name, libref = "WORK")
table_name |
string; Name of table in SAS. |
libref |
string; Name of libref SAS table is stored within. |
SAS only has two data types (numeric and character). Data types are converted as follows:
numeric -> double
character -> character
numeric (datetime, timezones are lost) -> POSIXct
numeric (date) -> POSIXct
In the conversion process dates and datetimes are converted to local
time. If utilizing another timezone, use attr(date, "tzone") <-
or
lubridate::with_tz()
to convert back to the desired time zone.
data.frame
of the specified SAS table.
## Not run: sas_connect() cars <- sas_to_r("cars", "sashelp") ## End(Not run)
## Not run: sas_connect() cars <- sas_to_r("cars", "sashelp") ## End(Not run)