Code Monkey home page Code Monkey logo

r-swat's Introduction

SAS Scripting Wrapper for Analytics Transfer (SWAT) for R

SWAT is an R package that enables you to interface with SAS Cloud Analytics Services (CAS), the in-memory server that is the centerpiece of the SAS Viya platform. Using the SWAT package, you can write an R program that connects to a CAS server, analyze large in-memory data sets, and then work with the results of the data analysis using familiar data-wrangling techniques in R.

This package provides facilities for starting a CAS session and running actions in CAS--such as classifying data with a decision tree or modeling with linear regression. Data processing is performed by CAS, which can scale from a single-machine server to distributed servers that run on multiple hosts and perform massively parallel processing.

Installation and Configuration

Requirements

To use the SWAT package for R, the client machine that runs R must meet the following requirements:

  • Use 64-bit Linux or 64-bit Windows.
  • Use a 64-bit version of R.
  • Use R 3.1.0 or later.
  • Install the dplyr, httr and jsonlite packages. These packages have additional dependencies that are automatically installed from CRAN when you run install.packages().

Installation

The SWAT package for R is available from SAS as a tar.gz file. You can download releases from https://github.com/sassoftware/R-swat/releases.

After you download the package, you can install the package with a command that is similar to the following:

R CMD INSTALL R-swat-X.X.X-platform.tar.gz

You can also install from within R directly using a URL.

# Make sure prerequisites are installed
> install.packages('dplyr')
> install.packages('httr')
> install.packages('jsonlite')

> install.packages('https://github.com/sassoftware/R-swat/releases/download/vX.X.X/R-swat-X.X.X-platform.tar.gz',
                   repos=NULL, type='file')

If you are running on a platform that does not have an associated installer, you should install the source code tar.gz. These platforms will be limited to using the CAS REST interface only.

> install.packages('https://github.com/sassoftware/R-swat/archive/vX.X.X.tar.gz', 
                   repos=NULL, type='file')

Connecting to CAS

Authinfo File

Using a .authinfo file is not required to use the package, but is recommended. When you enter your credentials (user ID and password) in a .authinfo file and secure the permissions, you can avoid specifying those credentials in programs.

Throughout the documentation, it is assumed that you have a .authinfo file. The following statement connects R to CAS and supplies the credentials from the .authinfo file:

conn <- swat::CAS('cloud.example.com', 8777, protocol='http')

If you do not use a .authinfo file, then you must connect with a statement like the following:

conn <- swat::CAS('cloud.example.com', 8777, protocol='http', username='sasdemo', password='!s3cret')

Binary and REST Communication

Communication between R and CAS can be performed in a binary format with proprietary C libraries, or over HTTP to a REST interface on the server. The C libraries (and therefore binary communication) are supported for 64-bit Linux or Windows only. Connections to CAS that use binary communication are similar to the following example:

conn <- swat::CAS('cloud.example.com', 5570)

Example

> library(swat)

# Connect to CAS
> conn <- swat::CAS('cloud.example.com', 8777)

# Load Iris data set into in-memory table
> iris.ct <- as.casTable(conn, iris)

# Use basic R functions on CAS table
> min(iris.ct$Sepal.Length)
[1] 4.3

> max(iris.ct$Sepal.Length)
[1] 7.9

> mean(iris.ct$Sepal.Length)
[1] 5.843333

# Call CAS actions on the table
> out <- cas.simple.summary(iris.ct)
> out
$Summary
        Column Min Max   N NMiss     Mean   Sum       Std     StdErr       Var
1 Sepal.Length 4.3 7.9 150     0 5.843333 876.5 0.8280661 0.06761132 0.6856935
2  Sepal.Width 2.0 4.4 150     0 3.057333 458.6 0.4358663 0.03558833 0.1899794
3 Petal.Length 1.0 6.9 150     0 3.758000 563.7 1.7652982 0.14413600 3.1162779
4  Petal.Width 0.1 2.5 150     0 1.199333 179.9 0.7622377 0.06223645 0.5810063
      USS       CSS       CV   TValue         ProbT
1 5223.85 102.16833 14.17113 86.42537 3.331256e-129
2 1430.40  28.30693 14.25642 85.90830 8.004458e-129
3 2582.71 464.32540 46.97441 26.07260  2.166017e-57
4  302.33  86.56993 63.55511 19.27060  2.659021e-42

# Explore results
> out$Summary[c('Column', 'Min', 'Max')]

If you get an error message about the TCP/IP negClientSSL support routine, you likely have an issue with your SSL certificate configuration. See the Encryption documentation (the R configuration is the same as the Python client) for more information.

r-swat's People

Contributors

bkemper24 avatar criptic avatar jld23 avatar pinduzera avatar poparksas avatar tomweber-sas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

r-swat's Issues

Skip run_iii when using n_thread =4

Hi there,
Thanks for your valuable package. When I want to run calibration with 700 run and with "n_thread =4", some of the run_iii is missed. So, there is a an error when I want to make a dotty plot (sensitive analysis). I have run 700 sample but there is 589 simulation.
In fact, one of the cores skype running.
The error code is that:
"Error in mutate():
! Problem while computing crit = crit.
x crit must be size 700 or 1, not 588."
Thanks in advance,
Hossein

Problem running example

Hi, thanks for your works connecting R and SAS.

I am tring to use this package running the example

   library(swat)
   swat::CAS('cloud.example.com', 8777, protocol='http', username='sasdemo', password='!s3cret')

but I recive the following error:

 Error in curl::curl_fetch_memory(url, handle = handle) : 
  Could not resolve host: cloud.example.com

plus to it when I call the swat library it tells me

NOTE: The extension module for using the CAS binary protocol can not be located.

do you know how could I solve this?

Package Swat not available for R version 3.2+

I have been trying to use Swat for a project in R but Swat only works on R versions that are 3.1 or lower. So I can't use it on any of the recent releases of R. Are there any plans to update the version of R that this package is able to run on?

How do I write an astore to a binary file?

The title explain pretty much everything. How do I write an downloaded astore to a file?

In python it's easy:

s.loadactionset('aStore')

astore_name = "_C80O7P8PJUOIEXTSRM5VBDJC1_ast"

store=s.download(rstore= {"name": astore_name, 
                          "caslib": "Models"})

with open('savelocal.sasast','wb') as file:
   file.write(store['blob'])

But in R the store file comes as a list, now raw . I've tried through RAW, bytes etc but didn't achieve much

loadActionSet(conn, "astore")

astore <- cas.astore.download(conn,
                    rstore =  list(name = astore_name, caslib = "Models")
                    )
class(astore) ### it's a list, simple saving it is not the binary astore. How do i do that?
filecon <- file("savelocal.sasast", "wb")

writeBin(astore, filecon) ## doesn't work, it only transforms vectors, not lists

If you can cover upload as well, because I can't figure out how to upload/read a blob in R

Thanks!

README installation instructions may require updating

Currently when you start RStudio using the AWS SAS training image the following code snippet is displayed in an R script

install.packages('https://github.com/sassoftware/r-swat/releases/download/vX.X.X/r-swat-X.X.X-platform.tar.gz')

This code and the R-swat README refers to r-swat in lower case. After checking the release page I found that the ‘r’ is upper case.

After I fixed that there were warnings when following the install instructions in the README (probably caused by the way RStudio and R are set up on the image and since the image has been wiped I cannot reproduce the exact code that I tried)

Warning: package is not available for R version 3.4.3

I got the swat package up and running using

install.packages('devtools')
library(devtools)
devtools::install_github(repo='sassoftware/R-swat')
library(swat)

Possible Actions

  • Recommend that the README be updated to have an upper-case r when referring to the repo or release R-swat.
  • It might also be useful to have the devtools instructions as an alternative install method for people who get stuck with all the other methods listed in the README.

Not able to Install R-swat-1.4.1-win64.tar.gz on windows client machine.

Hi,

I had able to setup Jupyter notebook can connect to CAS for Viya and we are good. Now I am trying to setup CAS to be run from R studio.

However, I have been following instructions from sassoftware github and stuck running below install package on my windows machine and given ERROR below.

install.packages('https://github.com/sassoftware/R-swat/releases/download/v1.4.1/R-swat-1.4.1-win64.tar.gz', repos=NULL, type='file')

install.packages('https://github.com/sassoftware/R-swat/releases/download/v1.4.1/R-swat-1.4.1-win64.tar.gz', repos=NULL, type='file')
trying URL 'https://github.com/sassoftware/R-swat/releases/download/v1.4.1/R-swat-1.4.1-win64.tar.gz'
Content type 'application/octet-stream' length 48621202 bytes (46.4 MB)
downloaded 46.4 MB

  • installing source package 'swat' ...
    ** libs
    running 'src/Makefile.win' ...
    installing to C:/Program Files/R/R-3.2.2/library/swat/libs/x64
    ** R
    ** preparing package for lazy loading
    Creating a generic function for 'print' from package 'base' in package 'swat'
    Creating a generic function for 'nrow' from package 'base' in package 'swat'
    Creating a generic function for 'ncol' from package 'base' in package 'swat'
    Creating a generic function for 'colnames' from package 'base' in package 'swat'
    Creating a generic function for 'rownames' from package 'base' in package 'swat'
    Creating a generic function for 'head' from package 'utils' in package 'swat'
    Creating a generic function for 'tail' from package 'utils' in package 'swat'
    Creating a generic function for 'subset.data.frame' from package 'base' in package 'swat'
    Creating a generic function for 'subset' from package 'base' in package 'swat'
    Creating a generic function for 'unique' from package 'base' in package 'swat'
    Creating a generic function for 'rbind' from package 'base' in package 'swat'
    Warning: package 'dplyr' was built under R version 3.2.5
    Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
    there is no package called 'DBI'
    Error : package or namespace load failed for 'dplyr'
    Error : unable to load R code in package 'swat'
    ERROR: lazy loading failed for package 'swat'
  • removing 'C:/Program Files/R/R-3.2.2/library/swat'
    Warning in install.packages :
    running command '"C:/PROGRA1/R/R-321.2/bin/x64/R" CMD INSTALL -l "C:\Program Files\R\R-3.2.2\library" "C:/Users/vt7/AppData/Local/Temp/RtmpIRQ29x/downloaded_packages/R-swat-1.4.1-win64.tar.gz"' had status 1
    Warning in install.packages :
    installation of package ‘C:/Users/vt7/AppData/Local/Temp/RtmpIRQ29x/downloaded_packages/R-swat-1.4.1-win64.tar.gz’ had non-zero exit status

Accessing CAS when running Viya on AWS

Hi,

I am struggling to use SWAT to access the CAS controller on Viya set up on AWS (we set up according to the following guide: https://github.com/aws-quickstart/quickstart-sas-viya).

Would you be able to point out any differences in the "swat::CAS((...)" command that we need to apply in order to connect and run R/Python?

We tried connecting to various IP addresses, but received the error "Empty reply from server" when using different options (port 8777 and port 5570).

Any help would be much appreciated.

Kind Regards,
Alex

CAS Connection returns error

SAS VIYA Version : 3.5
R version 3.2.3 (2015-12-10)
swat_1.6.3.9000
CentOS release 6.7

library('swat')
library('dplyr')
library('jsonlite')
library('httr')

Sys.setenv(CASCLIENTDEBUG=1)
options(cas.print.messages = TRUE)

Sys.setenv(CAS_CLIENT_SSL_CA_LIST="/home/xxx/SAS/xxx.pem")
conn <- CAS('server.domain', 5570, username="[email protected]", password="xxx")
[1] "NOTE: Client is using userid=[email protected], password=***"
[1] "NOTE: Client is using the userpass identity provider"
[1] "NOTE: Sent challenge length 132"
[1] "NOTE: Received response length 72"
[1] "NOTE: User [email protected] connected to CAS using user/pass."
NOTE: Connecting to CAS and generating CAS action functions for loaded
action sets...

Error in [.data.frame(table, c(setdiff(names(table), col.names), col.names)) :
undefined columns selected

sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS release 6.7 (Final)

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] httr_1.4.0 jsonlite_1.6 dplyr_0.8.3 swat_1.6.3.9000

loaded via a namespace (and not attached):
[1] Rcpp_1.0.3 crayon_1.3.4 assertthat_0.2.1 R6_2.4.0 magrittr_1.5 pillar_1.4.2 rlang_0.4.2
[8] curl_3.3 rstudioapi_0.10 tools_3.2.3 glue_1.3.1 purrr_0.3.2 pkgconfig_2.0.2 tidyselect_0.2.5
[15] tibble_2.1.3

Python SWAT works but status 807ff008 for R-SWAT on the same JupyterHub server

Hi experts,

Title is pretty much self explanatory.

Here are some extra details about the problem.

  • JupyterHub and CAS are residing on the same RHEL server.
  • Python-SWAT works just fine without any errors.
  • R-SWAT V1.4.0
  • Sys.getenv('CAS_CLIENT_SSL_CA_LIST') returns the desired destination of the .pem file
  • When running the following code:
    conn <- swat::CAS('Some.Random.Server', 5570, protocol='http', username='ABCDEFG', password='abcdefg')
    The following is the result:
    Error in curl::curl_fetch_memory(url, handle = handle) : Recv failure: Connection reset by peer
  • When running the following code:
    conn <- swat::CAS('Some.Random.Server', 5570)
    The following is the result:
    ERROR: The TCP/IP negClientSSL support routine failed with status 807ff008. ERROR: Failed to connect to host 'Some.Random.Server', port 5570. Error in swat::errorcheck(sw_error) : Could not connect to 'Some.Random.Server' on port 5570.

Hoping that someone has an idea what's going wrong...

Not available for 3.6.3 or 4.0.3

I tried install.packages('swat') for R versions 3.6.3 and 4.0.3 and it appears it is unavailable for either. Which version of R is necessary to install this package?

Connecting to CAS from R-SWAT fails with error: errorcheck(sw_value) : Could not decode table data

Hi All,
This is Ira, member of SAS Technical Support.

  1. I have a customer who opened a Track with us as he gets below error when connecting to CAS from R-SWAT. He performed the following steps
  • he installed R 4.3.1 on Windows 11
  • he installed required packages including 'dplyr', 'httr','jsonlite' and swat within R directly using URL
  • he imported Viya server certiciates into Windows
  • he created .authinfo file in %HOMEPATH% that contains:
    host avisia-cluster-02.localdomain user crapine password *************
  • Connect to CAS

library('swat')
SWAT 1.8.4
Sys.setenv(CASCLIENTDEBUG=1)
conn <- swat::CAS('avisia-cluster-02.localdomain', 5570)

[1] "NOTE: HOME: C:\Users\Avisia\OneDrive\Documents"
[1] "NOTE: HOMEDRIVE: C:"
[1] "NOTE: HOMEPATH: \Users\Avisia"
[1] "NOTE: Process owner identity is: DESKTOP-26DDQPG/Avisia"
[1] "NOTE: Reading authinfo file: C:\Users\Avisia\.authinfo"
[1] "NOTE: Matching host: avisia-cluster-02.localdomain"
[1] "NOTE: Matching port: 5570"
[1] "NOTE: Matching user: NONE"
[1] "NOTE: Using authinfo host definition: host avisia-cluster-02.localdomain user crapine password *********"
[1] "NOTE: Client is using userid=crapine, password=
"
[1] "NOTE: Client is using the userpass identity provider"
[1] "NOTE: Sent challenge length 138"
[1] "NOTE: Received response length 56"
[1] "NOTE: User crapine connected to CAS using user/pass."
NOTE: Connecting to CAS and generating CAS action functions for loaded
action sets...
Erreur dans swat::errorcheck(sw_value) : Could not decode table data.

  1. I have reproduced the problem on my environment. I have the same error.
    Erreur dans swat::errorcheck(sw_value) : Could not decode table data.

I have checked corresponding CAS log. I don't see any particular error.
INFO 2023-08-04 11:14:14.802 [cas] - MAIN irchum 486 [casgeneral.c:4997] - Launched session controller. Process ID is 14577. [index:00004750]
INFO 2023-08-04 11:14:14.846 [cas] - 14577 irchum MAIN [cas.c:2310] - Starting Cloud Analytic Services driver, host=viya35jm.ts.sashq-d.openstack.sas.com, id=0, role=session controller. [index:00000007]
INFO 2023-08-04 11:14:14.848 [cas] - 14577 irchum MAIN [tkcsesinst.c:748] - Successfully created session 0bfd4045-b371-eb40-857e-949b6e8e0eb1. [index:00000007]
INFO 2023-08-04 11:14:14.851 [cas] - 14577 irchum 486 [tkhttpserver.c:1353] - Starting HTTP server 'viya35jm.ts.sashq-d.openstack.sas.com', minPort=0 maxPort=0 [index:00000007]
INFO 2023-08-04 11:14:14.853 [cas] - 14577 irchum 486 [tkhttpserver.c:1438] - HTTP Server 'viya35jm.ts.sashq-d.openstack.sas.com' listening on port 36945. [index:00000007]
INFO 2023-08-04 11:14:14.877 [cas] - 14577 irchum 486 [cashttp.c:1936] - HTTP server is authenticating connections. [index:00000007]
INFO 2023-08-04 11:14:14.877 [cas] - 14577 irchum 486 [cashttp.c:1983] - HTTP server listening on HTTPS port 36945. [index:00000007]
INFO 2023-08-04 11:14:15.166 [cas] - 14577 irchum 486 [tkcasaimp.c:4504] - ++ action sessionProp.setFmtSearch / fmtLibNames={'CASFORMATS', 'PASCAL', 'SASSUPPLIEDFORMATS', 'ADDITIONALFORMATS'}; [index:00000007]
INFO 2023-08-04 11:14:15.167 [cas] - 14577 irchum 486 [tkcasaimp.c:6460] - -- 'sessionProp.setFmtSearch' SUCCESSFUL. [index:00000007]
NONE 2023-08-04 11:14:15.167 [cas] - INFO 14577 irchum 486 - 2.0_Consumption: CAS Action 'sessionProp.setFmtSearch' $ licensed cores 0, available cores 16, starting core 0 $ elapsed time 0.002117 seconds $ cpu time 0.001550 seconds (73.22%) $ total memory 125.75G $ memory 425.00K (0.00%) $ RC 0
INFO 2023-08-04 11:14:15.254 [cas] - 14577 irchum 486 [tkcasaimp.c:4504] - ++ action builtins.reflect / action='builtins.reflect', _messageLevel='error'; [index:00000007]
INFO 2023-08-04 11:14:15.255 [cas] - 14577 irchum 486 [tkcasaimp.c:6460] - -- 'builtins.reflect' SUCCESSFUL. [index:00000007]
NONE 2023-08-04 11:14:15.255 [cas] - INFO 14577 irchum 486 - 2.0_Consumption: CAS Action 'builtins.reflect' $ licensed cores 0, available cores 16, starting core 0 $ elapsed time 0.001132 seconds $ cpu time 0.001054 seconds (93.11%) $ total memory 125.75G $ memory 227.16K (0.00%) $ RC 0
INFO 2023-08-04 11:14:15.403 [cas] - 14577 irchum 486 [tkcasaimp.c:4504] - ++ action builtins.about / _messageLevel='error'; [index:00000007]
INFO 2023-08-04 11:14:15.403 [cas] - 14577 irchum 486 [tkcasalic.c:466] - Opening license file '/opt/sas/viya/config/etc/cas/default/sas_license.txt'. [index:00000007]

NONE 2023-08-04 11:14:15.407 [cas] - INFO 14577 irchum 486 - 2.0_Consumption: CAS Action 'builtins.about' $ licensed cores 0, available cores 16, starting core 0 $ elapsed time 0.004038 seconds $ cpu time 0.003985 seconds (98.69%) $ total memory 125.75G $ memory 388.22K (0.00%) $ RC 0

INFO 2023-08-04 11:14:15.407 [cas] - 14577 irchum 486 [tkcasaimp.c:6460] - -- 'builtins.about' SUCCESSFUL. [index:00000007]

NONE 2023-08-04 11:14:15.790 [vault] - {"time":"2023-08-04T09:14:15.789988593Z","type":"request","auth":{"client_token":"hmac-sha256:9d2db20255f9c099eef6adfa86ba38c529114d06ba4820baecb6e4e8a97d0684","accessor":"ihD0Zqoq2ZTQ7FiGeSZ31d6M","display_name":"token","policies":["default","pgpoolc"],"token_policies":["default","pgpoolc"],"token_type":"service"},"request":{"id":"0377110b-4ec0-dc9f-7293-9c5e91cdbc65","operation":"read","client_token":"hmac-sha256:9d2db20255f9c099eef6adfa86ba38c529114d06ba4820baecb6e4e8a97d0684","client_token_accessor":"ihD0Zqoq2ZTQ7FiGeSZ31d6M","namespace":{"id":"root"},"path":"secret/application/postgres/dba","remote_address":"10.104.81.73"}}

  1. The following JIRA was opeend for similar issue last year. The issue occurred when using R 4.2.0
    https://rndjira.sas.com/browse/COMPUTESVCS-35205

Do you have any thought on this issue?

Thanks
Ira

Parameter 'showLabels' error when connecting to CAS

Hi! I'm trying to connect to CAS using the following R code running in Rstudio. I have an authfile generated and the required packages are installed.

install(swat)
s <- CAS("my.host.com", 443, protocol='https')

However, I get this error:

NOTE: Connecting to CAS and generating CAS action functions for loaded
      action sets...
ERROR: Parameter 'showLabels' is not recognized.
ERROR: Expecting one of the following: actionSet, action, dynamicOptions.
ERROR: The action stopped due to errors.
Error in res$results[[1]] : subscript out of bounds

Any idea what's causing this error?

Methods that returns casDataFrame are failing

I've been noticing this since Swat 1.7 and now in 1.8 as well. I am using R 4.2.1
Sometimes it is just a warning and works as intended, but after a while, in the same session, it may become an error that just fails to return the tables to R (couldn't reproduce the second claim) and couldn't track the exact source.
But at least taking a look at the warnings would be good.

conn <- CAS(hostname = "myhost.com",
                username = "myuser",
                password = "mysecret")

##
hmeq <- read.csv("https://support.sas.com/documentation/onlinedoc/viya/exampledatasets/hmeq.csv")

ctbl <- as.casTable(conn, hmeq, casOut = list(replace = T))

> Warning messages:
> 1: In is.na(value) || is.nan(value) :
>   'length(x) = 13 > 1' in coercion to 'logical(1)'
> 2: In is.na(value) || is.nan(value) :
>   'length(x) = 13 > 1' in coercion to 'logical(1)'
> 3: In is.na(value) || is.nan(value) || value == missval :
>   'length(x) = 13 > 1' in coercion to 'logical(1)'

cas.max(ctbl)

> Warning messages:
> 1: In is.na(value) || is.nan(value) :
>   'length(x) = 13 > 1' in coercion to 'logical(1)'
> 2: In is.na(value) || is.nan(value) :
>   'length(x) = 13 > 1' in coercion to 'logical(1)'
> 3: In is.na(value) || is.nan(value) || value == missval :
>   'length(x) = 13 > 1' in coercion to 'logical(1)'

cas.table.columnInfo(ctbl[,1:4]) ## subsetting columns before sending the action

> Warning messages:
> 1: In is.na(value) || is.nan(value) :
>   'length(x) = 4 > 1' in coercion to 'logical(1)'
> 2: In is.na(value) || is.nan(value) :
>   'length(x) = 4 > 1' in coercion to 'logical(1)'
> 3: In is.na(value) || is.nan(value) || value == missval :
>   'length(x) = 4 > 1' in coercion to 'logical(1)'

Add casOut="mytablename" support to cas.read.xxx functions

One of the features of SAS Cloud Analytic Services, is parameter coercion. The current signature of cas.read.csv (for example) supports the following use:

mytable <- cas.read.csv(conn, "/path/to/my/R/client/file.csv", casOut=list(name="mytable"))

Because of parameter coercion, the function should be able to support the following use:

mytable <- cas.read.csv(conn, "/path/to/my/R/client/file.csv", casOut="mytable")

I've added this issue to request support for casOut="character" and casOut=list() support to the cas.read.xxx functions.

gen.functions, get action set case from the server instead of the user

In gen.functions, we reuse what the user typed in for the action set (TABLE or Table) when generating functions instead of reading it off the result that comes back from listActions.

x <- casRetrieve(s, "listActions" actionSet="Table")
ls(x$results)
[1] "table"

We want cas.table.loadTable() instead of cas.Table.loadTable().

How to setup SSO from R-Studio to access CAS?

Hi team,
I'm part of SAS Technical Support. I have a customer asking how to setup SSO from R-Studio to access CAS.
The customer is using SWAT on JupyterHub. SSO from JupyterHub to CAS has been implemented. They can connect to CAS from R-Studio except SSO access. They ask if it is possible to have the same SSO feature as JupyterHub. They couldn't find any information about it on the GitHub and developer.sas.com pages. Is it supported? Do you have the documentation ?

Thanks
Ira

retrieving count(*) from fedSQL query doesn't work correctly

Hi,

When issuing a fedSQL group by query with count(*), the count(*) column that is retrieved has the same value in every row (correct value for first row).

Example:
cas.fedSql.execDirect(conn, query="SELECT job, count(*) as cnt FROM casuser.hmeq GROUP BY job ORDER BY job;")

R

The correct result when using Python-swat:
conn.fedSql.execDirect(query="SELECT job, count(*) as cnt FROM casuser.hmeq GROUP BY job ORDER BY job;")

Python

rbind.casTable not binding 2 CAStables

rbind.casTable not binding 2 CASTables, one is supposed to be updated that because I didn't want to drop the table to update it.

I'm trying to bind 2 CASTables but it keeps saying that 2 objects aren't CAStables even though I'm sure that they are.

class(nf_ctbl)
'CASTable'
class(ctbl)
'CASTable'

rbind.casTable(ctbl, nf_ctbl) 

Error in rbind.casTable(ctbl, nf_ctbl): This function must take two or more casTables
Traceback:

1. rbind.casTable(ctbl, nf_ctbl)
2. stop("This function must take two or more casTables")
are.

CAS.read_sql in SWAT R

Is there any equivalent to function read_sql in python-swat for r-swat or is it planned to add function like that?

Upload date format column to CAS

In Data Frame, one column is date format.
Can I upload to CAS while maintaining the date format?
For now, just upload the date format, then it read in varchar format.

I am creating a job that uploads preprocessed data in R.
However, because the Plan of Prepare Data is executed in Viya(convert varchar to date), the data linked with the report is not updated automatically.
If i upload the data from R to CAS while maintaining the date column type, i don't need to execute the Plan of Prepare Data step.
So i simply upload the data from R to CAS and make the data associated with the report update automatically.

I am uploading data with the following code.

as.casTable(conn, dataframe, casOut=list(name="NEGO_AGG_R", caslib='PUBLIC', promote=TRUE))

Convert DataFrame to CAS dataframe using as.casDataFrame,
Can I convert a column types to Date with an option?
Or is there another method?

as.casDataFrame(df, name = "", label = "", title = "", attrs = list(),
col.labels = "", col.formats = "", col.attrs = list(),
col.sizes = list(), col.types = "", col.widths = 0)

Error when closing and reopening a connection to CAS

While using RSWAT in RStudio I will establish a connection using syntax such as:

# Establish Connection
s <- swat::CAS("CONNECTION/TO/MY/INSTANCE",
               username='MYUSER', password='MYPASS')

I then perform some work. However, if I close this connection, as so cas.close(s), and try to establish the same connection again in the same instance of RStudio, I will often received the following error:

NOTE: Connecting to CAS and generating CAS action functions for loaded
      action sets...
Error in if (result$disposition$severity > 1) { : 
  argument is of length zero

The only was I can re-establish the connection is to close and reopen RStudio.

Any idea as to what this error is trying to tell me? Thanks!

Connecting to CAS using swat in R results to SSL error

Hi,

Trying to connect to CAS from R studio. But encountering SSL errors.

We installed the trustedcerts.pem from the viya server to the Trusted Root Certification Authority of the desktop.
Also added System environment variable CAS_CLIENT_SSL_CA_LIST.

Below are the code and log:

library(swat)
Sys.setenv(CAS_CLIENT_SSL_CA_LIST="C:/Users/41274/R and Python Enablement/trustedcerts.pem")
conn_binary <- CAS('mpviyaorccs01.mbtc.mgc.local', 5570, username="", password="XXXXXXXX")
[1] "ERROR: The TCP/IP negClientSSL support routine failed with error 32760 (An unexpected error has occurred. Error number is 32760.), Port 5570, Host 10.131.4.22"
[1] "ERROR: Failed to connect to host 'mpviyaorccs01.mbtc.mgc.local', port 5570."
Error in ans@ref :
no applicable method for @ applied to an object of class "NULL"
Sys.time()
[1] "2023-06-22 16:43:25 CST"
conn_binary <- CAS('mpviyaorccs01.mbtc.mgc.local', 5570, protocol='https', "", password="XXXXXXXX")
Error in curl::curl_fetch_memory(url, handle = handle) :
schannel: failed to receive handshake, SSL/TLS connection failed
Sys.time()
[1] "2023-06-22 16:43:29 CST"
conn_rest <- CAS('mpviyaorccs01.mbtc.mgc.local', 8777, protocol='https', "", password="XXXXXXXX")
Error in doTryCatch(return(expr), name, parentenv, handler) :
https://mpviyaorccs01.mbtc.mgc.local:8777/cas/sessions : HTTP/1.1 401 Unauthorized
Sys.time()
[1] "2023-06-22 16:43:35 CST"

Appreciate any advise.
Thanks

summary() on CAS table throws Error

When using the summary() function on a CAS table I get the following error:

> library(swat)
SWAT 1.5.0
> conn <- CAS(...)
NOTE: Connecting to CAS and generating CAS action functions for loaded
      action sets...
NOTE: To generate the functions with signatures (for tab completion), set 
      options(cas.gen.function.sig=TRUE).
> iris_ct <- as.casTable(conn, iris)
> summary(iris_ct)
Error: `x` must be a vector, not a `casDataFrame` object.
Run `rlang::last_error()` to see where the error occurred.
> rlang::last_error()
<error/vctrs_error_scalar_type>
`x` must be a vector, not a `casDataFrame` object.
Backtrace:
  1. base::summary(iris_ct)
  2. swat::summary(iris_ct)
  3. swat:::.local(object, ...)
  4. freqres$results$Frequency
 11. dplyr::select(., Column, FmtVar, Frequency)
 13. tidyselect::eval_select(expr(c(...)), .data)
 14. tidyselect:::eval_select_impl(...)
 15. vctrs::vec_assert(x)
 16. vctrs:::stop_scalar_type(x, arg)
 17. vctrs:::stop_vctrs(msg, "vctrs_error_scalar_type", actual = x)
Run `rlang::last_trace()` to see the full context.

However, in case of the iris data set, when excluding the Species column summary() works:

> summary(iris_ct[,c('Sepal.Width','Sepal.Length', 'Petal.Length', 'Petal.Width')])
  Sepal.Width     Sepal.Length    Petal.Length    Petal.Width   
 Min.   :2.000   Min.   :4.300   Min.   :1.000   Min.   :0.100  
 1st Qu.:2.800   1st Qu.:5.100   1st Qu.:1.600   1st Qu.:0.300  
 Median :3.000   Median :5.800   Median :4.350   Median :1.300  
 Mean   :3.057   Mean   :5.843   Mean   :3.758   Mean   :1.199  
 3rd Qu.:3.300   3rd Qu.:6.400   3rd Qu.:5.100   3rd Qu.:1.800  
 Max.   :4.400   Max.   :7.900   Max.   :6.900   Max.   :2.500

Error while installing R-SWAt inside K8s cluster Viya 4

I am getting error while installing R-SWAT into Kubernetes cluster,
I have followed below 2 methods to install,

Method 1: Mounted sas-pyconfig mount on Linux machine outside k8s cluster

  1. mounted ./saspyconfig directory outisde cluster on Linux machine
  2. ran install command
  3. It fails to launch R because, we only have access to R inside container

Method 2: Inside CAS container

  1. Launched a session to get inside CAS container
  2. Was able to launch R inside container
  3. While running install command for R-swat, it fails with write permission error for Librarary folder inside /opt/sas/viya/home/sas-pyconfig/default_r/Lib64/R/, so it is asking to install in some other directory.

Please help
How to install R-SWAT in k8s cluster

to.casDataFrame returns json parsing error

Hi, I'm trying to bring a CAS table into R Studio using RSWAT. The table has 382k rows and 35 columns. However, when I tried to use (obs=) in the statement, I encountered a Json error. Please see the attached file.
Rswat
When I removed obs=, the code ran successfully but only returned 32k instead of 382k rows for me which is not desirable. Is there any advice on how to fix this problem?

dataStep.runCode action set failing

When calling the dataStep runCode actionset, R client is failing to fetch a result. The error is on the client side because if you try to use ctbl <- defCasTable(con, "a", caslib = "casuser") you will have the table correctly created.

library("swat")

con <- CAS(..., protocol = "http")

ds1 <- "data casuser.a;

        do i = 1 to 1000;
            j = i + 1;
            output;
        end;
  put 'Hello from ' _hostname_  'thread # '   _threadid_;
  run;
  "

cas.dataStep.runCode(con, code = ds1)

Which gives the following error:

Error in value[[3L]](cond) : 
  Error in names(out) <- col.names: 'names' attribute [4] must be the same length as the vector [0]

  • This happens from Viya 3.5 up to newest Viya 4, since it is a R client error (1.8.1 and 1.8.3 tested)

  • The error happens in the R6 Class REST_CASTable in the toVectors method (rswat_rest.R row 175).

  • This is only REST interface error.

My suspicion is that it R-SWAT expects that CAS returns a table, but since it calls a dataStep and does not fetch any results. Not sure if the easy path is to return an empty list or check how to retrieve the same info as the cas protocol.

When using the binary/cas protocol, we get the following response:

$InputCasTables
[1] casLib  Name    Rows    Columns
<0 rows> (or 0-length row.names)

$OutputCasTables
           casLib Name  Rows Columns Append Promoted
1 CASUSER(edhell)    a 16000       2    NaN        N

table.fileInfo not working

Hi,

the fileInfo action does not seem to work for R-SWAT releases v1.6.3 and v1.6.4-snapshot tested on Viya 2021.2.1:

R-SWAT fileInfo

Best regards

summary() does not work on CASTable

Hi folks,

I got an error message when calling the overloaded summary function on a CASTable. Could you take a look when you have time?

Thanks,
Yue

> library("swat")
NOTE: The extension module for binary protocol support is not available.
      Only the CAS REST interface can be used.
SWAT 1.2.0.9000
> conn <- CAS('rdcgrdc.unx.sas.com', 63596)
NOTE: Connecting to CAS and generating CAS action functions for loaded
      action sets...
NOTE: To generate the functions with signatures (for tab completion), set 
      options(cas.gen.function.sig=TRUE).
> iris_ct <- as.casTable(conn,iris,casOut = list(replace = TRUE))
NOTE: Cloud Analytic Services made the uploaded file available as table IRIS in caslib CASUSERHDFS(sasyqi).
> head(iris_ct)
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa
> summary(iris_ct)
Error in freqres$results$Frequency %>% select(Column, FmtVar, Frequency) %>%  : 
  could not find function "%>%"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.