├── .Rbuildignore ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── ContributorAgreement.txt ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R ├── CASdf.R ├── CAStab.R ├── Ops.R ├── action.R ├── analytical_functions.R ├── authinfo.R ├── connection_viewer.R ├── datetime.R ├── descriptive_stats.R ├── graphics.R ├── helper.R ├── read_write.R ├── rswat.R ├── rswat_rest.R ├── swat.R └── table_functions.R ├── README.md ├── SUPPORT.md ├── cicd ├── generate-tox-ini.py ├── get-basename.py ├── get-host.py ├── get-protocol.py ├── get-server-info.py ├── get-version.py ├── get-workspace-url.py ├── install-tk.py ├── promote-release-candidate.py ├── stage-release-candidate.py ├── tar2conda.py └── upload-assests.py ├── conda.recipe ├── meta.yaml └── test_package.R ├── inst ├── icons │ └── sas.png └── rstudio │ ├── connections.dcf │ └── connections │ └── CAS.R ├── man ├── CAS-class.Rd ├── CASTable-Extract.Rd ├── CASTable-class.Rd ├── as.casDataFrame.Rd ├── as.casTable.Rd ├── cas.close.Rd ├── cas.count.Rd ├── cas.css.Rd ├── cas.cv.Rd ├── cas.max.Rd ├── cas.mean.Rd ├── cas.median.Rd ├── cas.min.Rd ├── cas.mode.Rd ├── cas.nmiss.Rd ├── cas.probt.Rd ├── cas.quantile.Rd ├── cas.read.csv.Rd ├── cas.read.jmp.Rd ├── cas.read.sas7bdat.Rd ├── cas.read.table.Rd ├── cas.read.xlsx.Rd ├── cas.readRDS.Rd ├── cas.saveRDS.Rd ├── cas.sd.Rd ├── cas.stderr.Rd ├── cas.sum.Rd ├── cas.terminate.Rd ├── cas.tvalue.Rd ├── cas.upload.Rd ├── cas.upload.file.Rd ├── cas.upload.frame.Rd ├── cas.uss.Rd ├── cas.var.Rd ├── cas.write.csv.Rd ├── cas.write.csv2.Rd ├── cas.write.table.Rd ├── cas.write.xlsx.Rd ├── casDataFrame-class.Rd ├── casFormula.Rd ├── casRetrieve.Rd ├── cbind.casTable.Rd ├── cbind2.casTable.Rd ├── colMeans-CASTable-method.Rd ├── colSums-CASTable-method.Rd ├── colnames-CASTable-method.Rd ├── cor-CASTable-method.Rd ├── cov-CASTable-method.Rd ├── defCasTable.Rd ├── dim-CASTable-method.Rd ├── dimnames-CASTable-method.Rd ├── dropTable.Rd ├── generatedFunctions.Rd ├── head-CASTable-method.Rd ├── is.castable.Rd ├── length-CASTable-method.Rd ├── listActionParms.Rd ├── listActionSets.Rd ├── loadActionSet.Rd ├── max-CASTable-method.Rd ├── mean-CASTable-method.Rd ├── median-CASTable-method.Rd ├── min-CASTable-method.Rd ├── names-CASTable-method.Rd ├── ncol-CASTable-method.Rd ├── nrow-CASTable-method.Rd ├── rbind-CASTable-method.Rd ├── rbind.casTable.Rd ├── rbind2.casTable.Rd ├── rownames-CASTable-method.Rd ├── runAction.Rd ├── show-casDataFrame-method.Rd ├── subset.casTable.Rd ├── summary-CASTable-method.Rd ├── swat.Rd ├── tail-CASTable-method.Rd ├── to.casDataFrame.Rd ├── to.data.frame.Rd ├── to.r.data.frame.Rd └── unique-CASTable-method.Rd ├── tests ├── data │ ├── census2.sas7bdat │ ├── class.csv │ ├── class.dlm │ ├── class.dta │ ├── class.jmp │ ├── class.rds │ ├── effort.txt │ ├── effort.xlsx │ ├── effort_cas.xlsx │ ├── excel_test.xlsx │ ├── hr_comma_sep.csv │ ├── hr_semicolon_sep.csv │ └── missing_vals.txt ├── testthat.R └── testthat │ ├── helper.data_load.R │ ├── test.analysis_compvars.R │ ├── test.cas_tab.R │ ├── test.compvars_where.R │ ├── test.connection.R │ ├── test.datetime.R │ ├── test.descriptive_stats.R │ ├── test.general_functions.R │ ├── test.graphics.R │ ├── test.helper.R │ ├── test.operator_indexing.R │ ├── test.rbind.R │ ├── test.read_write.R │ ├── test.rswat.R │ └── test.table_functions.R └── tox.ini /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Editor temporary/working/backup files 2 | .#* 3 | *\#*\# 4 | [#]*# 5 | *~ 6 | *$ 7 | *.bak 8 | *.old 9 | *flymake* 10 | *.kdev4 11 | *.log 12 | *.nfs* 13 | *.swn 14 | *.swo 15 | *.swp 16 | *.pdb 17 | .project 18 | .pydevproject 19 | .settings 20 | .idea 21 | .vagrant 22 | .noseids 23 | .ipynb_checkpoints 24 | .tags 25 | .vscode 26 | .nfs* 27 | 28 | ## Compiled source 29 | *.a 30 | *.com 31 | *.class 32 | *.dll 33 | *.dylib 34 | *.exe 35 | *.o 36 | *.py[ocd] 37 | *.so 38 | *.na 39 | .build_cache_dir 40 | MANIFEST 41 | 42 | ## Python files 43 | # setup.py working directory 44 | build 45 | # sphinx build directory 46 | doc/_build 47 | # setup.py dist directory 48 | dist 49 | # Egg metadata 50 | *.egg-info 51 | .eggs 52 | .pypirc 53 | 54 | ## tox testing tool 55 | .tox 56 | # rope 57 | .ropeproject 58 | # wheel files 59 | *.whl 60 | **/wheelhouse/* 61 | # coverage 62 | .coverage 63 | swat.egg-info/ 64 | __pycache__/ 65 | _stats.txt 66 | cover/ 67 | test-reports/ 68 | 69 | ## OS generated files 70 | .directory 71 | .gdb_history 72 | .DS_Store 73 | ehthumbs.db 74 | Icon? 75 | Thumbs.db 76 | 77 | ## Documentation generated files 78 | doc/build 79 | doc/source/generated 80 | 81 | ## R files 82 | ..Rcheck 83 | .Rproj.user 84 | .Rhistory 85 | .RData 86 | .Ruserdata 87 | *.Rproj -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Change Log 3 | 4 | ## 1.10.0 - 2024-12-05 5 | 6 | - Update TK subsystem 7 | 8 | ## 1.9.0 - 2023-09-22 9 | 10 | - Update TK subsystem 11 | - Fix issue running with R4.2 and later on Windows 12 | 13 | ## 1.8.4 - 2023-06-06 14 | 15 | - Fix Issue #46 dataStep action failing on Rest Protocol 16 | 17 | ## 1.8.3 - 2023-02-02 18 | 19 | - Fix problem handling empty list during request processing 20 | 21 | ## 1.8.2 - 2023-01-10 22 | 23 | - Fix problem handling empty list during response processing 24 | 25 | ## 1.8.1 - 2023-01-06 26 | 27 | - Fix calls to the percentile action set to be compliant with the removal of table.vars 28 | - Fix logical warnings from methods that return casDataFrame 29 | - Fix unit testing for summary generic method 30 | - Throw an error instead of returning an empty list when trying to use a data.frame inside a cas.actionset.action 31 | 32 | ## 1.8.0 - 2022-11-14 33 | 34 | - Update TK subsystem 35 | 36 | ## 1.7.0 - 2022-07-12 37 | 38 | - Add to.r.data.frame function to convert a CAS Table to an R Data Frame 39 | - Cleanup swat object memory 40 | - Update TK subsystem 41 | 42 | ## 1.6.3 - 2021-08-11 43 | 44 | - Fix duplicate action parameter issue 45 | - Fix integer issue in table to data.frame converter 46 | 47 | ## 1.6.2 - 2021-06-18 48 | 49 | - Add authorization code style of authentication 50 | 51 | ## 1.6.1 - 2021-05-10 52 | 53 | - Improve CAS result table to `data.frame` performance 54 | - Fix blob support in REST interface 55 | - Add support for RStudio connections 56 | - Improve libssl / libcrypto detection 57 | 58 | ## 1.6.0 - 2021-01-13 59 | 60 | - Fix binary parameters and downloads 61 | - Remove extra dependencies (dplyr, random) 62 | - Improve connection parameter parsing and add `CAS_URL` environment variable support 63 | - Improve performance of initial server connection 64 | 65 | ## 1.5.0 - 2020-06-08 66 | 67 | - Add support for R v4.0 68 | - Improve unit testing framework 69 | - Add blob result value support 70 | 71 | ## 1.4.1 - 2019-12-02 72 | 73 | - Improve connection URL parsing and default ports 74 | - Fix issue with generated wrapper parameters 75 | - Add caslibs to rbind function 76 | 77 | ## 1.4.0 - 2018-09-18 78 | 79 | - Add support for binary protocol on Windows 80 | - Fix problem when explicitly specifying authinfo file 81 | 82 | ## 1.3.0 - 2018-07-25 83 | 84 | - Add support for By group sets in rbind.bygroups 85 | - Improve error reporting if no connection object is available for action call 86 | - Display error if specified authinfo file is missing 87 | 88 | ## 1.2.1 - 2018-06-05 89 | 90 | - Added options for handling By groups 91 | - Added rbind.bygroups for concatenating data.frames in CAS results containing By groups 92 | - Added cas.terminate and cas.close functions for closing connections 93 | - Added cas.upload, cas.upload.file, and cas.upload.frame functions for uploading data 94 | - Added performance, severity, statusCode, reason, status, messages, and events fields to CAS object 95 | - Improved performance of summary function 96 | - Improve error reporting 97 | 98 | ## 1.2.0 - 2018-01-24 99 | 100 | - Improve controller failover support 101 | - Add encryption support to REST interface 102 | - Improvements to data selection, orderby and groupby in CAS table objects 103 | - Fix issues related to new columns in new correlation action 104 | 105 | ## 1.1.0 - 2017-10-13 106 | 107 | - Add common help page for all CAS actions 108 | - Add support for controller failover and integer missing values 109 | - Fixes for cor and cov 110 | - Improved handling of computed variables 111 | - Added additional tests 112 | - Handling of int64s to vectors instead of lists 113 | 114 | ## 1.0.0 - 2017-05-01 115 | 116 | - CAS object for connecting to SAS Cloud Analytic Services (CAS) 117 | - Automatically generated functions for calling CAS actions. 118 | - CAS table object for interacting and invoking actions on CAS in-memory tables. 119 | - Support for creating CAS tables using R-style data readers, as well as data.frame-like access to CAS tables. 120 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # SAS SWAT Developer How-To 2 | 3 | Developing SWAT using the REST interface is just like developing any 4 | other project on GitHub. You clone the project, do your work, 5 | and submit a pull request. However, the binary interface is a bit 6 | different since it requires the bundled SAS TK libraries an R 7 | C extension modules. 8 | 9 | ## Developing Against the Binary CAS Interface 10 | 11 | In order to run against CAS using the binary interface, you must copy 12 | the C libraries from a platform-specific distribution to your git 13 | clone. These files are located in the swat/src/ directory. 14 | So to develop on Linux, you would clone SWAT from GitHub, download the 15 | Linux-specific tar.gz file, unzip it, and copy the swat/src/\*.so 16 | files to your clone directory. From that point on, you should be able 17 | to connect to both REST and binary CAS ports from your clone. 18 | 19 | ## Submitting a Pull Request 20 | 21 | Submitting a pull request uses the standard process at GitHub. 22 | Note that in the submitted changes, there must always be a unit test 23 | for the code being contributed. Pull requests that do not have a 24 | unit test will not be accepted. 25 | 26 | You also must include the text from the ContributerAgreement.txt file 27 | along with your sign-off verifying that the change originated from you. 28 | 29 | ## Testing 30 | 31 | For the most part, testing the SAS SWAT package is just like testing 32 | any other R package. Tests are written using the testthat package. 33 | 34 | Since CAS is a network resource and requires authentication, there is 35 | some extra setup involved in getting your tests configured to run 36 | against your CAS server. Normally this involves setting the following 37 | environment variables. 38 | 39 | * CASHOST - the hostname or IP address of your CAS server (Default: None) 40 | * CASPORT - the port of your CAS server (Default: None) 41 | * CASPROTOCOL - the protocol being using ('cas', 'http', 'https'; Default: 'cas') 42 | 43 | * CASUSER - the CAS account username (Default: None) 44 | * CASPASSWORD - the CAS account password (Default: None) 45 | 46 | You can set these environment variables within your R sessions as follows: 47 | 48 | Sys.setenv(CASHOST='myhost.com') 49 | Sys.setenv(CASPORT=5570) 50 | Sys.setenv(CASPROTOCOL='cas') 51 | 52 | Some of these can alternatively be specified using configuration files. 53 | The CASHOST, CASPORT, and CASPROTOCOL variables can be specified in a .casrc 54 | in your home directory (or in any directory from the directory you are 55 | running from all the way up to your home directory). It is actually written 56 | in Lua, but the most basic form is as follows: 57 | 58 | cashost = 'myhost.com' 59 | casport = 5570 60 | casprotocol = 'cas' 61 | 62 | The CASUSER and CASPASSWORD variables are usually extracted from your 63 | `~/.authinfo` file automatically. The only reason you should use environment 64 | variables is if you have a generalized test running account that is 65 | shared across various tools. 66 | 67 | Once you have these setup, you can use tools like devtools to run the suite: 68 | 69 | devtools::test() 70 | 71 | You can also run each test individually using profiling as follows: 72 | 73 | testthat::test_file('path/to/test-file.R') 74 | -------------------------------------------------------------------------------- /ContributorAgreement.txt: -------------------------------------------------------------------------------- 1 | Contributor Agreement 2 | 3 | Version 1.1 4 | 5 | Contributions to this software are accepted only when they are 6 | properly accompanied by a Contributor Agreement. The Contributor 7 | Agreement for this software is the Developer's Certificate of Origin 8 | 1.1 (DCO) as provided with and required for accepting contributions 9 | to the Linux kernel. 10 | 11 | In each contribution proposed to be included in this software, the 12 | developer must include a "sign-off" that denotes consent to the 13 | terms of the Developer's Certificate of Origin. The sign-off is 14 | a line of text in the description that accompanies the change, 15 | certifying that you have the right to provide the contribution 16 | to be included. For changes provided in source code control (for 17 | example, via a Git pull request) the sign-off must be included in 18 | the commit message in source code control. For changes provided 19 | in email or issue tracking, the sign-off must be included in the 20 | email or the issue, and the sign-off will be incorporated into the 21 | permanent commit message if the contribution is accepted into the 22 | official source code. 23 | 24 | If you can certify the below: 25 | 26 | Developer's Certificate of Origin 1.1 27 | 28 | By making a contribution to this project, I certify that: 29 | 30 | (a) The contribution was created in whole or in part by me and I 31 | have the right to submit it under the open source license 32 | indicated in the file; or 33 | 34 | (b) The contribution is based upon previous work that, to the best 35 | of my knowledge, is covered under an appropriate open source 36 | license and I have the right under that license to submit that 37 | work with modifications, whether created in whole or in part 38 | by me, under the same open source license (unless I am 39 | permitted to submit under a different license), as indicated 40 | in the file; or 41 | 42 | (c) The contribution was provided directly to me by some other 43 | person who certified (a), (b) or (c) and I have not modified 44 | it. 45 | 46 | (d) I understand and agree that this project and the contribution 47 | are public and that a record of the contribution (including all 48 | personal information I submit with it, including my sign-off) is 49 | maintained indefinitely and may be redistributed consistent with 50 | this project or the open source license(s) involved. 51 | 52 | then you just add a line saying 53 | 54 | Signed-off-by: Random J Developer 55 | 56 | using your real name (sorry, no pseudonyms or anonymous contributions.) 57 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: swat 2 | Type: Package 3 | Title: SAS Scripting Wrapper for Analytics Transfer (SWAT) 4 | Version: 1.10.0.9000 5 | TKVersion: none 6 | Date: 06JUN2020 7 | Authors@R: c(person("Jared", "Dean", role = c("aut", "cre"), 8 | email = "Jared.Dean@sas.com"), 9 | person("Tom", "Weber", role = "aut", email = "Tom.Weber@sas.com"), 10 | person("Kevin", "Smith", role = "aut", email = "Kevin.Smith@sas.com")) 11 | Author: Jared Dean [aut, cre], 12 | Tom Weber [aut, cre], 13 | Kevin Smith [aut] 14 | Maintainer: Kevin Smith 15 | Description: SWAT provides an R scripting interface to SAS Cloud Analytic Services (CAS). 16 | This enables R programmers to perform analytical functions provided by SAS. 17 | License: file LICENSE 18 | Copyright: Copyright 2017 SAS Institute Inc. All Rights Reserved. 19 | Issues: Enter issues at https://github.com/sassoftware/r-swat/issues. 20 | Depends: 21 | R (>= 3.1.0) 22 | Suggests: 23 | testthat, 24 | xlsx, 25 | knitr 26 | Imports: 27 | httr, 28 | jsonlite, 29 | tools, 30 | methods 31 | Collate: 32 | 'datetime.R' 33 | 'rswat.R' 34 | 'authinfo.R' 35 | 'rswat_rest.R' 36 | 'swat.R' 37 | 'helper.R' 38 | 'CAStab.R' 39 | 'table_functions.R' 40 | 'descriptive_stats.R' 41 | 'action.R' 42 | 'CASdf.R' 43 | 'read_write.R' 44 | 'analytical_functions.R' 45 | 'graphics.R' 46 | 'Ops.R' 47 | 'connection_viewer.R' 48 | RoxygenNote: 6.0.1 49 | VignetteBuilder: knitr 50 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(cbind,casTable) 4 | export(.cas.arith) 5 | export(.cas.compare) 6 | export(.cas.logic) 7 | export(.getConnectionInfo) 8 | export(CASwhere) 9 | export(as.casDataFrame) 10 | export(as.casTable) 11 | export(cas.close) 12 | export(cas.count) 13 | export(cas.css) 14 | export(cas.cv) 15 | export(cas.max) 16 | export(cas.mean) 17 | export(cas.median) 18 | export(cas.min) 19 | export(cas.mode) 20 | export(cas.nmiss) 21 | export(cas.probt) 22 | export(cas.quantile) 23 | export(cas.read.csv) 24 | export(cas.read.jmp) 25 | export(cas.read.sas7bdat) 26 | export(cas.read.table) 27 | export(cas.read.xlsx) 28 | export(cas.readRDS) 29 | export(cas.saveRDS) 30 | export(cas.sd) 31 | export(cas.stderr) 32 | export(cas.sum) 33 | export(cas.terminate) 34 | export(cas.tvalue) 35 | export(cas.upload) 36 | export(cas.upload.file) 37 | export(cas.upload.frame) 38 | export(cas.uss) 39 | export(cas.var) 40 | export(cas.write.csv) 41 | export(cas.write.csv2) 42 | export(cas.write.table) 43 | export(cas.write.xlsx) 44 | export(casDataFrame) 45 | export(casFormula) 46 | export(cbind2.casTable) 47 | export(check_for_cas_errors) 48 | export(defCasTable) 49 | export(dropTable) 50 | export(gen.table.parm) 51 | export(is.castable) 52 | export(listActionParms) 53 | export(listActionSets) 54 | export(loadActionSet) 55 | export(numericVarList) 56 | export(rbind.bygroups) 57 | export(rbind.casTable) 58 | export(rbind2.casTable) 59 | export(runAction) 60 | export(subset.casTable) 61 | export(to.casDataFrame) 62 | export(to.data.frame) 63 | export(to.r.data.frame) 64 | export(translate) 65 | export(uniqueTableName) 66 | exportClasses(CAS) 67 | exportClasses(CASDataMsgHandler) 68 | exportClasses(CASTable) 69 | exportClasses(casDataFrame) 70 | exportMethods("!") 71 | exportMethods("!=") 72 | exportMethods("$") 73 | exportMethods("$<-") 74 | exportMethods("%%") 75 | exportMethods("%/%") 76 | exportMethods("&") 77 | exportMethods("*") 78 | exportMethods("+") 79 | exportMethods("-") 80 | exportMethods("/") 81 | exportMethods("<") 82 | exportMethods("<=") 83 | exportMethods("==") 84 | exportMethods(">") 85 | exportMethods(">=") 86 | exportMethods("[") 87 | exportMethods("[<-") 88 | exportMethods("[[") 89 | exportMethods("^") 90 | exportMethods("|") 91 | exportMethods(cbind2) 92 | exportMethods(colMeans) 93 | exportMethods(colSums) 94 | exportMethods(colnames) 95 | exportMethods(cor) 96 | exportMethods(cov) 97 | exportMethods(dim) 98 | exportMethods(dimnames) 99 | exportMethods(head) 100 | exportMethods(initialize) 101 | exportMethods(length) 102 | exportMethods(max) 103 | exportMethods(mean) 104 | exportMethods(median) 105 | exportMethods(min) 106 | exportMethods(names) 107 | exportMethods(ncol) 108 | exportMethods(nrow) 109 | exportMethods(rbind) 110 | exportMethods(rbind2) 111 | exportMethods(rownames) 112 | exportMethods(show) 113 | exportMethods(subset) 114 | exportMethods(subset.data.frame) 115 | exportMethods(summary) 116 | exportMethods(tail) 117 | exportMethods(unique) 118 | exportPattern("^[[:alpha:]]+") 119 | if ( grepl('linux', R.version$os) ) {useDynLib(rswat)} 120 | importFrom("methods", "as", "callNextMethod", "is", "new", "setClass", "setGeneric", "slot", "initialize", "show") 121 | importFrom("utils", "read.csv", "read.table", "str", "write.csv", "write.csv2", "write.table") 122 | -------------------------------------------------------------------------------- /R/analytical_functions.R: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright SAS Institute 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the License); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | 17 | sasDecisionTree <- function(x, formula=NULL, target="", inputs="", nominals="", 18 | crit="gain", maxlevel=6L, leafsize=5L, missing="useInSearch", assessment=TRUE, event=""){ 19 | 20 | if (exists("formula") & class(formula)=='formula') { 21 | f1 <- swat::casFormula(formula, x) 22 | target <-toString(f1[1]) 23 | inputs <-f1[[2]] 24 | } 25 | 26 | # Are there nominals 27 | if (length(nominals)>1 || nchar(nominals)>0){ 28 | nom <- as.list(nominals) 29 | res <-runAction(x, "decisionTree.dtreeTrain", check_errors=TRUE, inputs=as.list(inputs), target=target, casout = list(name=paste(x@tname, "_modelout", sep=''), replace=TRUE), 30 | encodeName=TRUE, nominals=nom, crit=crit, prune=TRUE, stat=TRUE, varImp=TRUE, missing=toupper(missing)) 31 | } 32 | else { 33 | res <-runAction(x, "decisionTree.dtreeTrain", check_errors=TRUE, inputs=as.list(inputs), target=target, 34 | crit=crit, prune=TRUE, varImp=TRUE, stat=TRUE, missing=toupper(missing)) 35 | } 36 | #check_for_cas_errors(res) 37 | res$call <- match.call() 38 | vars = c(x@names, x@computedVars) 39 | vars = vars[vars != ""] 40 | score <- runAction(x, "decisionTree.dtreeScore", check_errors=TRUE, 41 | target=target, 42 | encodeName=TRUE, 43 | copyVars=as.list(vars), 44 | modelTable=paste(x@tname, "_modelout", sep=''), 45 | casout = list(name=paste(x@tname, "_scoreout", sep=''), replace=TRUE)) 46 | #check_for_cas_errors(score) 47 | # define score CAS table 48 | score_out <- defCasTable(x@conn,toString(score$OutputCasTables[2])) 49 | if (assessment==TRUE){ 50 | if (paste("I_",target,sep='') %in% colnames(score_out)){ 51 | nom_target = TRUE 52 | stopifnot(nchar(score_out@tname)>0 & nchar(event)>0) 53 | assess <- runAction(score_out@conn, 54 | "percentile.assess", check_errors=TRUE, 55 | table=list(name=score_out@tname), 56 | inputs=as.list(trimws(score$EncodedName[trimws(score$EncodedName$LEVNAME)==event,3])), 57 | pvar=as.list(trimws(score$EncodedName[! trimws(score$EncodedName$LEVNAME)==event,3])), 58 | event = trimws(score$EncodedName[trimws(score$EncodedName$LEVNAME)==event,1]), 59 | pevent=as.list(trimws(score$EncodedName[! trimws(score$EncodedName$LEVNAME)==event,1])), 60 | response=target, 61 | casout=list(name=paste(x@tname, "_lift", sep=''), replace=TRUE), 62 | fitstatout=list(name=paste(x@tname, "_fitstat", sep=''), replace=TRUE), 63 | rocout=list(name=paste(x@tname, "_roc", sep=''), replace=TRUE) 64 | ) 65 | #check_for_cas_errors(assess) 66 | res$roc <- defCasTable(x@conn,toString(assess$OutputCasTables[2,2])) 67 | 68 | } 69 | else { 70 | nom_target = FALSE 71 | } 72 | check_for_cas_errors(assess) 73 | res$lift <- defCasTable(x@conn,toString(assess$OutputCasTables[1,2])) 74 | res$fitstat <- defCasTable(x@conn,toString(assess$OutputCasTables[3,2])) 75 | } 76 | res$score <- score 77 | sasCode <- runAction(x@conn, "decisionTree.dtreeCode", check_errors=TRUE, modelTable=paste(x@tname, "_modelout", sep='')) 78 | #check_for_cas_errors(sasCode) 79 | res$sasCode <- sasCode 80 | return(res) 81 | } 82 | 83 | sasDecisionForest <- function(x, formula=NULL, target="", inputs="", nominals="", 84 | crit="gain", maxlevel=6L, leafsize=5L, missing="useInSearch", 85 | ntree=50, vote="majority", bootstrap=.632120559 ){ 86 | 87 | if (exists("formula") & class(formula)=='formula') { 88 | f1 <- swat::casFormula(formula, x) 89 | target <-toString(f1[1]) 90 | inputs <-f1[[2]] 91 | } 92 | 93 | # Are there nominals 94 | if (length(nominals)>1 || nchar(nominals)>0){ 95 | nom <- as.list(nominals) 96 | res <-runAction(x, "decisionTree.forestTrain", check_errors=TRUE, inputs=as.list(inputs), target=target, 97 | nominals=nom, crit=crit, prune=TRUE, varImp=TRUE, missing=toupper(missing), 98 | nTree=ntree, bootstrap=bootstrap, vote=toupper(vote) ) 99 | } 100 | else { 101 | res <-runAction(x, "decisionTree.forestTrain", check_errors=TRUE, inputs=as.list(inputs), target=target, 102 | crit=crit, prune=TRUE, varImp=TRUE, missing=toupper(missing), 103 | nTree=ntree, bootstrap=bootstrap, vote=toupper(vote)) 104 | } 105 | #check_for_cas_errors(res) 106 | 107 | return(res) 108 | } 109 | -------------------------------------------------------------------------------- /R/authinfo.R: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright SAS Institute 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the License); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | 17 | query_authinfo <- function( hostname, username=NULL, protocol=NULL, filepath=NULL ) 18 | { 19 | hosts <- list() 20 | host <- NULL 21 | skipnext <- FALSE 22 | path_sep <- .Platform$path.sep 23 | file_sep <- .Platform$file.sep 24 | 25 | if ( !is.null(username) && username == '' ) { 26 | username <- NULL 27 | } 28 | 29 | if ( !is.null(protocol) && protocol == '' ) { 30 | protocol <- NULL 31 | } 32 | 33 | # Construct possible list of authinfo/netrc files 34 | authinfo_paths <- c('_authinfo.gpg', '.authinfo.gpg', '_netrc.gpg', '.netrc.gpg', 35 | '_authinfo', '.authinfo', '_netrc', '.netrc') 36 | if ( .Platform$OS.type == 'windows' ) 37 | { 38 | homedir <- paste(Sys.getenv('HOMEDRIVE'), Sys.getenv('HOMEPATH'), sep='') 39 | } 40 | else 41 | { 42 | homedir <- Sys.getenv('HOME') 43 | } 44 | 45 | if ( homedir == '' ) 46 | { 47 | homedir <- path.expand('~') 48 | } 49 | 50 | if ( is.null(filepath) ) 51 | { 52 | if ( nchar(Sys.getenv('AUTHINFO')) > 0 ) 53 | { 54 | authinfo_paths <- strsplit(Sys.getenv('AUTHINFO'), path_sep)[[1]] 55 | for ( i in 1:length(authinfo_paths) ) 56 | { 57 | authinfo_paths[[i]] <- path.expand(authinfo_paths[[i]]) 58 | } 59 | } 60 | else if ( nchar(Sys.getenv('NETRC')) > 0 ) 61 | { 62 | authinfo_paths <- strsplit(Sys.getenv('NETRC'), path_sep)[[1]] 63 | for ( i in 1:length(authinfo_paths) ) 64 | { 65 | authinfo_paths[[i]] <- path.expand(authinfo_paths[[i]]) 66 | } 67 | } 68 | else 69 | { 70 | for ( i in 1:length(authinfo_paths) ) 71 | { 72 | authinfo_paths[[i]] <- paste(homedir, authinfo_paths[[i]], sep=file_sep) 73 | } 74 | } 75 | } 76 | else 77 | { 78 | authinfo_paths <- filepath 79 | for ( i in 1:length(filepath) ) 80 | { 81 | authinfo_paths[[i]] <- path.expand(authinfo_paths[[i]]) 82 | } 83 | } 84 | 85 | map_protocol <- function( p ) 86 | { 87 | if ( is.null(p) ) { 88 | return( NULL ) 89 | } 90 | if ( class(p) == 'numeric' || class(p) == 'integer' ) { 91 | return( p ) 92 | } 93 | if ( tolower(p) == 'http' ) { 94 | p <- 80 95 | } 96 | else if ( tolower(p) == 'https' ) { 97 | p <- 443 98 | } 99 | else { 100 | p <- as.integer(p) 101 | } 102 | return( p ) 103 | } 104 | 105 | protocol <- map_protocol(protocol) 106 | 107 | for ( i in 1:length(authinfo_paths) ) 108 | { 109 | if ( !file.exists(authinfo_paths[[i]]) ) 110 | { 111 | next 112 | } 113 | 114 | info <- scan(authinfo_paths[[i]], character(0), comment.char='#', 115 | blank.lines.skip=TRUE, quiet=TRUE) 116 | 117 | for ( i in 1:length(info) ) 118 | { 119 | token <- info[[i]] 120 | 121 | if ( skipnext ) 122 | { 123 | skipnext <- FALSE 124 | next 125 | } 126 | 127 | if ( token == 'host' || token == 'machine' ) 128 | { 129 | if ( !is.null(host) && length(names(host)) ) 130 | { 131 | hosts[[length(hosts) + 1]] <- host 132 | } 133 | host <- list() 134 | host[['hostname']] <- tolower(info[[i + 1]]) 135 | skipnext <- TRUE 136 | } 137 | else if ( token == 'default' ) 138 | { 139 | if ( !is.null(host) && length(names(host)) ) 140 | { 141 | hosts[[length(hosts) + 1]] <- host 142 | } 143 | host <- list() 144 | host[['hostname']] <- '*' 145 | } 146 | else if ( token == 'password' ) 147 | { 148 | host[['password']] <- info[[i + 1]] 149 | skipnext <- TRUE 150 | } 151 | else if ( token == 'login' || token == 'user' || token == 'account' ) 152 | { 153 | host[['username']] <- info[[i + 1]] 154 | skipnext <- TRUE 155 | } 156 | else if ( token == 'port' || token == 'protocol' ) 157 | { 158 | host[['port']] <- map_protocol(info[[i + 1]]) 159 | skipnext <- TRUE 160 | } 161 | else 162 | { 163 | skipnext <- TRUE 164 | } 165 | } 166 | 167 | if ( !is.null(host) && length(names(host)) ) 168 | { 169 | hosts[[length(hosts) + 1]] <- host 170 | } 171 | 172 | for ( i in 1:length(hosts) ) 173 | { 174 | host <- hosts[[i]] 175 | 176 | if ( (host$hostname == hostname || host$hostname == '*') && 177 | (is.null(host$username) || is.null(username) || host$username == username) && 178 | (is.null(host$port) || is.null(protocol) || host$port == protocol) ) 179 | { 180 | return( host ) 181 | } 182 | } 183 | } 184 | 185 | return( NULL ) 186 | } 187 | -------------------------------------------------------------------------------- /R/connection_viewer.R: -------------------------------------------------------------------------------- 1 | # List available server actions 2 | .connection_actions <- function(connection) { 3 | icons <- system.file(file.path("icons"), package = "swat") 4 | list( 5 | Help = list( 6 | icon = file.path(icons, "help.png"), 7 | callback = function() { 8 | utils::browseURL("https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=v_010&docsetId=caspg3r&docsetTarget=titlepage.htm&locale=en") 9 | } 10 | ) 11 | ) 12 | } 13 | 14 | .on_connection_opened <- function(connection, code) { 15 | observer <- getOption("connectionObserver") 16 | if (is.null(observer)) 17 | return(invisible(NULL)) 18 | 19 | observer$connectionOpened( 20 | connectionObject = connection, 21 | 22 | type = "CAS", 23 | 24 | host = .host_spec(connection), 25 | 26 | icon = system.file(file.path("icons", "sas.png"), package = "swat"), 27 | 28 | displayName = .host_spec(connection), 29 | 30 | connectCode = code, 31 | 32 | disconnect = function() { 33 | cas.session.endSession(connection) 34 | cas.close(connection) 35 | }, 36 | 37 | previewObject = function(rowLimit, ...) { 38 | .connection_preview_table(connection, rowLimit, ...) 39 | }, 40 | 41 | listObjectTypes = function() { 42 | return(list(caslib = list(contains = list(table = list(contains = "data"), 43 | view = list(contains = "data"))))) 44 | }, 45 | 46 | listObjects = function(...) { 47 | return(.connection_list_objects(connection, ...)) 48 | }, 49 | 50 | listColumns = function(...) { 51 | .connection_list_columns(connection, ...) 52 | }, 53 | 54 | actions = .connection_actions(connection) 55 | ) 56 | } 57 | 58 | .on_connection_closed <- function(connection) { 59 | observer <- getOption("connectionObserver") 60 | if (is.null(observer)) 61 | return(invisible(NULL)) 62 | observer$connectionClosed("CAS", .host_spec(connection)) 63 | } 64 | 65 | .on_connection_updated <- function(connection, hint) { 66 | observer <- getOption("connectionObserver") 67 | if (is.null(observer)) 68 | return(invisible(NULL)) 69 | observer$connectionUpdated("CAS", .host_spec(connection), hint = hint) 70 | } 71 | 72 | .connection_is_open <- function(connection) { 73 | return(connection$isConnected()) 74 | } 75 | 76 | .connection_list_objects <- function(connection, ...) { 77 | if (is.null(connection) || !.connection_is_open(connection)) 78 | return(character()) 79 | 80 | args <- list(...) 81 | 82 | # Display tables for a specific caslib 83 | if (!is.null(args$caslib)) { 84 | out <- cas.table.tableInfo(connection, caslib = args$caslib, `_messageLevel` = "error") 85 | if (is.null(out$TableInfo)) 86 | return(character()) 87 | 88 | out <- out$TableInfo@df 89 | 90 | types <- out$View 91 | types[types == 0] <- "table" 92 | types[types == 1] <- "view" 93 | 94 | if (length(types) > 0) { 95 | out <- data.frame(name = out$Name, type = types, stringsAsFactors = FALSE) 96 | return(out[order(out$name), ]) 97 | } 98 | } 99 | 100 | # Display all caslibs 101 | out <- cas.table.caslibInfo(connection, `_messageLevel` = "error") 102 | if (is.null(out$CASLibInfo)) 103 | return(character()) 104 | 105 | out <- out$CASLibInfo@df 106 | 107 | types <- rep("caslib", dim(out)[1]) 108 | if (length(types) > 0) { 109 | out <- data.frame(name = out$Name, type = types, stringsAsFactors = FALSE) 110 | return(out[order(out$name), ]) 111 | } 112 | 113 | character() 114 | } 115 | 116 | .connection_list_columns <- function(connection, ...) { 117 | if (!is.null(connection) && .connection_is_open(connection)) { 118 | args <- list(...) 119 | 120 | if (!is.null(args$view)) { 121 | table <- args$view 122 | } else { 123 | table <- args$table 124 | } 125 | 126 | out <- cas.table.columnInfo(connection, table = list(name = table, caslib = args$caslib), 127 | `_messageLevel` = "error") 128 | if (is.null(out$ColumnInfo)) 129 | return(NULL) 130 | 131 | out <- out$ColumnInfo@df 132 | 133 | return(data.frame(name = out$Column, type = out$Type, stringsAsFactors = FALSE)) 134 | } 135 | NULL 136 | } 137 | 138 | .connection_preview_table <- function(connection, limit, ...) { 139 | if (!is.null(connection) && .connection_is_open(connection)) { 140 | args <- list(...) 141 | 142 | if (!is.null(args$view)) { 143 | table <- args$view 144 | } else { 145 | table <- args$table 146 | } 147 | 148 | out <- cas.table.fetch(connection, table = list(name = table, caslib = args$caslib), 149 | to = limit, index = FALSE, `_messageLevel` = "error") 150 | if (is.null(out$Fetch)) 151 | return(NULL) 152 | 153 | return(out$Fetch@df) 154 | } 155 | NULL 156 | } 157 | 158 | .host_spec <- function(connection) { 159 | return(connection$hostname[[1]]) 160 | } 161 | -------------------------------------------------------------------------------- /R/datetime.R: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright SAS Institute 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the License); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | 17 | 18 | 19 | .casdt.total.seconds <- function ( cts ) 20 | { 21 | if ( class(cts) == 'character' && grepl('^-?\\d{9}\\d*$', cts, perl=TRUE) ) 22 | cts <- as.numeric(gsub('^(-?\\d+)(\\d{6})$', '\\1.\\2', cts, perl=TRUE)) 23 | else 24 | cts <- as.numeric(cts) / 1000000 25 | return( cts ) 26 | } 27 | 28 | # 29 | # Convert CAS datetimes to R / SAS datetimes 30 | # 31 | 32 | cas2rPOSIXlt <- function ( cts ) 33 | { 34 | return( as.POSIXlt(cas2rPOSIXct(cts)) ) 35 | } 36 | 37 | cas2rPOSIXct <- function ( cts ) 38 | { 39 | return( as.POSIXct(.casdt.total.seconds(cts), origin='1960-01-01', tz='UTC') ) 40 | } 41 | 42 | cas2rDate <- function ( cdt ) 43 | { 44 | return( as.Date(as.POSIXct(as.numeric(cdt) * 60 * 60 * 24, origin='1960-01-01', tz='UTC')) ) 45 | } 46 | 47 | casTime2rPOSIXct <- function ( ctm ) 48 | { 49 | return( as.POSIXct(.casdt.total.seconds(ctm), origin='1970-01-01', tz='UTC') ) 50 | } 51 | 52 | casTime2rPOSIXlt <- function ( ctm ) 53 | { 54 | return( as.POSIXlt(casTime2rPOSIXct(ctm)) ) 55 | } 56 | 57 | rPOSIXlt2cas <- function ( rplt ) 58 | { 59 | return( (as.numeric(rplt) + 3653 * 24 * 60 * 60 ) * 1000000 ) 60 | } 61 | 62 | rPOSIXct2cas <- function ( rpct ) 63 | { 64 | return( (as.numeric(rpct) + 3653 * 24 * 60 * 60 ) * 1000000 ) 65 | } 66 | 67 | rDate2cas <- function ( rdt ) 68 | { 69 | return( as.numeric(rdt) + 3653 ) 70 | } 71 | 72 | cas2sasDateTime <- function ( cts ) 73 | { 74 | return( .casdt.total.seconds(cts) ) 75 | } 76 | 77 | cas2sasDate <- function ( cdt ) 78 | { 79 | return( cdt ) 80 | } 81 | 82 | cas2sasTime <- function ( ctm ) 83 | { 84 | return( .casdt.total.seconds(ctm) ) 85 | } 86 | 87 | # 88 | # Convert SAS datetimes to R / SAS datetimes 89 | # 90 | 91 | sas2rPOSIXlt <- function ( sts ) 92 | { 93 | return( as.POSIXlt(sas2rPOSIXct(sts)) ) 94 | } 95 | 96 | sas2rPOSIXct <- function ( sts ) 97 | { 98 | return( as.POSIXct(as.numeric(sts), origin='1960-01-01', tz='UTC') ) 99 | } 100 | 101 | sas2rDate <- function ( sdt ) 102 | { 103 | return( as.Date(as.POSIXct(as.numeric(sdt) * 60 * 60 * 24, origin='1960-01-01', tz='UTC')) ) 104 | } 105 | 106 | sasTime2rPOSIXct <- function ( stm ) 107 | { 108 | return( as.POSIXct(as.numeric(stm), origin='1970-01-01', tz='UTC') ) 109 | } 110 | 111 | sasTime2rPOSIXlt <- function ( stm ) 112 | { 113 | return( as.POSIXlt(sasTime2rPOSIXct(stm)) ) 114 | } 115 | 116 | rPOSIXlt2sas <- function ( rplt ) 117 | { 118 | return( as.numeric(rplt) + 3653 * 24 * 60 * 60 ) 119 | } 120 | 121 | rPOSIXct2sas <- function ( rpct ) 122 | { 123 | return( as.numeric(rpct) + 3653 * 24 * 60 * 60 ) 124 | } 125 | 126 | rDate2sas <- function ( rdt ) 127 | { 128 | return( as.numeric(rdt) + 3653 ) 129 | } 130 | 131 | sas2casDateTime <- function ( sts ) 132 | { 133 | return( as.numeric(sts) * 1000000 ) 134 | } 135 | 136 | sas2casDate <- function ( sdt ) 137 | { 138 | return( sdt ) 139 | } 140 | 141 | sas2casTime <- function ( stm ) 142 | { 143 | return( as.numeric(stm) * 1000000 ) 144 | } 145 | -------------------------------------------------------------------------------- /R/graphics.R: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright SAS Institute 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the License); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | 17 | 18 | setMethod("plot", 19 | signature(x = "CASTable"), 20 | function (x, y, ...) 21 | { 22 | stopifnot(class(y)=='CASTable' & x@tname==y@tname) 23 | downloadObs <- as.numeric(getOption('cas.max.download.rows')) 24 | # did the user override the download size 25 | allargs <- list(...) 26 | for (i in seq(length(allargs))){ 27 | if ("downloadObs" %in% attributes(allargs)$names) { 28 | downloadObs <- allargs$downloadObs 29 | } 30 | } 31 | 32 | vars = c(x@names, y@names) 33 | vars = vars[vars != ""] 34 | if (length(vars) == 0) 35 | vars = "" 36 | cvars = c(x@computedVars, y@computedVars) 37 | cvars = cvars[cvars != ""] 38 | if (length(cvars) == 0) 39 | { 40 | cvars = "" 41 | cpgm = "" 42 | } 43 | else 44 | { 45 | cpgm = c(x@computedVarsProgram, y@computedVarsProgram) 46 | cpgm = cpgm[cpgm != ""] 47 | if (length(cpgm) > 1) 48 | cpgm = paste(cpgm, collapse=';') 49 | } 50 | v2 <- x 51 | v2@names = c(vars, cvars) 52 | v2@names = v2@names[v2@names != ""] 53 | v2@computedVars = cvars 54 | v2@computedVarsProgram = cpgm 55 | 56 | 57 | # if the number of observations is less than download size 58 | if (nrow(x) <= downloadObs){ 59 | t1 <-to.casDataFrame(v2) 60 | return(plot(t1,...=...)) 61 | } 62 | else{ 63 | # sample rows 64 | if (length(x@groupby)){ # SRS 65 | name <- uniqueTableName(x@tname) 66 | res <- runAction(x@conn, "sampling.srs", check_errors=TRUE, 67 | samppct=eval(downloadObs/nrow(x)*100), 68 | table=x@tname, 69 | output=list(casOut=list(name=name, 70 | replace=TRUE), copyvars=list(vars)) 71 | ) 72 | #check_for_cas_errors(res) 73 | srs <- defCasTable(x@conn, name, columns = vars, where = x@where, 74 | orderby = x@orderby, groupby = x@groupby, gbmode = x@gbmode) 75 | m1 <-paste("sampling (SRS) was done prior to", sys.call(1), "because the nrows in", nrow(x), "which is greater than the max download size of", downloadObs) 76 | cat(m1[1]) 77 | srs2 <- to.casDataFrame(srs, obs=eval(nrow(srs))) 78 | return(plot(srs2, ... = ...)) 79 | } 80 | else { # Stratified 81 | name <- uniqueTableName(x@tname) 82 | res <- runAction(x@conn, "sampling.srs", check_errors=TRUE, 83 | samppct=eval(downloadObs/nrow(x)*100), 84 | table=x@tname, 85 | output=list(casOut=list(name=name, 86 | replace=TRUE), copyvars=list(vars)) 87 | ) 88 | #check_for_cas_errors(res) 89 | srs <- defCasTable(x@conn, name, columns = vars, where = x@where, 90 | orderby = x@orderby, groupby = x@groupby, gbmode = x@gbmode) 91 | m1 <-paste("sampling (Stratified) was done prior to", sys.call(1), "because the nrows in", nrow(x), "which is greater than the max download size of", downloadObs) 92 | cat(m1[1]) 93 | srs2 <- to.casDataFrame(srs, obs=eval(nrow(srs))) 94 | return(plot(srs2, ... = ...)) 95 | 96 | } 97 | } 98 | } 99 | ) 100 | -------------------------------------------------------------------------------- /R/helper.R: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright SAS Institute 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the License); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | 17 | # Translate CAS result data frame to list 18 | # 19 | # This is an internal function to aid in formating results as \R users expect. 20 | #' @keywords internal 21 | #' @export 22 | #' @rawRd % Copyright SAS Institute 23 | # 24 | # results <- cas.simple.summary(irisct) 25 | # translate(results$Summary) 26 | # translate(results$Summary, col='Mean') 27 | translate <- function(df, col = 2L) { 28 | if (is.data.frame(df)) 29 | x <- as.vector(t(df[, col])) 30 | names(x) <- as.list(df[, 1]) 31 | return (x) 32 | } 33 | 34 | #' @keywords internal 35 | #' @export 36 | #' @rawRd % Copyright SAS Institute 37 | uniqueTableName <- function(prefix = "") { 38 | a <- gsub('\\', '/', tempfile(prefix), fixed=TRUE) 39 | b <- strsplit(a, split = '/') 40 | return (as.character(lapply(b, tail, n = 1L))) 41 | } 42 | 43 | 44 | # Generate Table Parameters 45 | # 46 | #' @keywords internal 47 | #' @export 48 | #' @rawRd % Copyright SAS Institute 49 | # 50 | # tp = swat::gen.table.parm(x) 51 | gen.table.parm <- function(ct) { 52 | tp <- list() 53 | if (class(ct) == 'CASTable') tp[['name']] <- ct@tname 54 | if (!is.null(ct@caslib) && ct@caslib != '' ) tp[['caslib']] <- ct@caslib 55 | if (!is.null(ct@where) && ct@where != '' ) tp[['where']] <- ct@where 56 | if (!is.null(ct@orderby) && length(ct@orderby)) tp[['orderby']] <- ct@orderby 57 | if (!is.null(ct@groupby) && length(ct@groupby)) tp[['groupby']] <- ct@groupby 58 | if (!is.null(ct@gbmode) && ct@gbmode != '' ) tp[['groupbymode']] <- ct@gbmode 59 | 60 | # if (length(ct@computedVars) > 1 || ct@computedVars != "") 61 | if (sum(nchar(ct@computedVars))) 62 | { 63 | if (sum(nchar(ct@XcomputedVars))) 64 | { 65 | cmpvars <- ct@computedVars 66 | for(Xcmp in ct@XcomputedVars) 67 | if (!(Xcmp %in% ct@computedVars)) 68 | cmpvars = c(cmpvars, Xcmp) 69 | tp[['computedVars']] <- c(cmpvars) 70 | } 71 | else 72 | tp[['computedVars']] <- c(ct@computedVars) 73 | 74 | tp[['computedOnDemand']] <- ct@computedOnDemand 75 | tp[['computedVarsProgram']] <- paste(paste(ct@computedVarsProgram,collapse=';'),';',sep='') 76 | 77 | if (length(ct@names) > 1 || nchar(ct@names)) 78 | tp[['vars']] <- c(ct@names) 79 | } 80 | else 81 | { 82 | if (length(ct@names) > 1 || nchar(ct@names)) 83 | tp[['vars']] <- c(ct@names) 84 | if (sum(nchar(ct@XcomputedVars))) 85 | { 86 | tp[['computedVars']] <- c(ct@XcomputedVars) 87 | tp[['computedVarsProgram']] <- paste(paste(ct@computedVarsProgram,collapse=';'),';',sep='') 88 | } 89 | } 90 | 91 | if ((!sum(nchar(ct@XcomputedVars))) & sum(nchar(ct@XcomputedVarsProgram))) 92 | { 93 | cw = paste(ct@XcomputedVarsProgram, sep='', collapse=' AND ') 94 | if (ct@where != '') 95 | tp[['where']] <- paste('(', ct@where, ' AND ', cw, ')', sep='') 96 | else 97 | tp[['where']] <- cw 98 | } 99 | 100 | return (tp) 101 | } 102 | 103 | 104 | # Check if CAS Submission had Errors 105 | # 106 | # The function scans the result messages from CAS to see if they contain and ERROR string. 107 | # There is an optional argument stop.on.error which defaults to TRUE. which will stop processing, 108 | # if set to FALSE a warning will be displayed and processing will continue 109 | # 110 | # @param result the result to check 111 | # @param stop.on.error should an error in the CAS log raise and exception 112 | # 113 | # @return Boolean 114 | #' @keywords internal 115 | #' @export 116 | #' @rawRd % Copyright SAS Institute 117 | # check_for_cas_errors(res) 118 | check_for_cas_errors <- function(result, stop.on.error = TRUE) { 119 | if ( result$disposition$severity > 1 ) { 120 | if (stop.on.error) { 121 | msgs = '' 122 | for (msg in result$messages) 123 | msgs = paste(msgs, msg[], '\n', sep='') 124 | stop( 125 | paste( 126 | "\nError message(s) found in CAS action results:", 127 | deparse(sys.call(-1)), 128 | msgs, sep = "\n" 129 | ) 130 | ) 131 | } 132 | else{ 133 | msgs = '' 134 | for (msg in result$messages) 135 | msgs = paste(msgs, msg[], '\n', sep='') 136 | warning( 137 | paste( 138 | "\nError message(s) found in CAS action results:", 139 | deparse(sys.call(-1)), 140 | msgs, sep = "\n" 141 | ) 142 | ) 143 | } 144 | } 145 | } 146 | 147 | #https://ww2.coastal.edu/kingw/statistics/R-tutorials/formulae.html 148 | #' CAS Function to extract information from an \R formula object 149 | #' 150 | #' @param f1 a formula object 151 | #' 152 | #' @return list with target and inputs as members 153 | #' @export 154 | #' @rawRd % Copyright SAS Institute 155 | #' @keywords internal 156 | #' 157 | casFormula <- function(f, ct) { 158 | if (class(f) != "formula") { 159 | stop("must be a formula") 160 | } 161 | else{ 162 | # is there a target or just inputs 163 | if (length(f) == 3) { 164 | target <- f[[2]] 165 | i_index = 3 166 | } 167 | else{ 168 | target <- NULL 169 | i_index = 2 170 | } 171 | s1 <- deparse(f[[i_index]]) 172 | if (s1 == ".") { 173 | # remove target from list 174 | ci <- grep(as.character(target), names(ct)) 175 | ct <- ct[-ci] 176 | # format names list to string for later processing 177 | s0 <- as.character(names(ct)) 178 | s1 <- paste(s0, collapse=' + ') 179 | } 180 | 181 | # check for non-supported formula operators 182 | s2 <- grep("[*:]", s1, ignore.case = TRUE) 183 | if (length(s2) == 0) { 184 | inputs <- lapply(strsplit(s1, '\\+'), trimws) 185 | } 186 | else { 187 | stop("unsupported formula operators found") 188 | } 189 | } 190 | return (list(target, inputs[[1]])) 191 | } 192 | 193 | #' @export 194 | #' @rawRd % Copyright SAS Institute 195 | #' @keywords internal 196 | CASwhere <- function(ct, s) { 197 | # s <- "ct$n4 > 15 & df$n1 < 6" 198 | # string $ operator and prior string 199 | a <- gsub("\\b\\w+\\$", " ", s, perl = TRUE) 200 | 201 | # convert !, &, || 202 | b <- gsub("&", "and", a) 203 | c <- gsub("!", "not", b) 204 | d <- gsub("\\|", "or", c) 205 | e <- gsub("==", "=", d) 206 | 207 | # pad the string with one space to test last token 208 | e <- paste(e, ' ', sep='') 209 | 210 | vars = c(ct@names, ct@computedVars) 211 | vars = vars[vars != ""] 212 | 213 | for (name in vars) { 214 | pat <- paste("\\s", name, '\\s', sep='') 215 | e = gsub(pat, paste('"', name, '"n', sep=''), e, ignore.case =TRUE, perl=TRUE) 216 | } 217 | return(e) 218 | } 219 | 220 | #' @keywords internal 221 | #' @export 222 | #' @rawRd % Copyright SAS Institute 223 | numericVarList <- function(object) { 224 | tp = gen.table.parm(object) 225 | if (sum(nchar(tp$computedVars))) 226 | { 227 | tp$vars = c(tp$vars, tp$computedVars) 228 | tp$vars = tp$vars[tp$vars != ""] 229 | } 230 | res <- casRetrieve(object@conn, 'columninfo', table = tp) 231 | d = dim(res$results$ColumnInfo) 232 | ret = list() 233 | nvars = list() 234 | cvars = list() 235 | for (i in 1:d[1]) 236 | { 237 | if (res$results$ColumnInfo$Column[i] %in% c(object@names, object@computedVars)) 238 | { 239 | if (res$results$ColumnInfo$Type[i] %in% c('double', 'int32', 'int64')) 240 | nvars = c(nvars, res$results$ColumnInfo$Column[i]) 241 | else 242 | cvars = c(cvars, res$results$ColumnInfo$Column[i]) 243 | } 244 | } 245 | return (nvars) 246 | } 247 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SAS Scripting Wrapper for Analytics Transfer (SWAT) for R 2 | 3 | SWAT is an R package that enables you to interface with 4 | SAS Cloud Analytics Services (CAS), the in-memory server that is 5 | the centerpiece of the [SAS Viya](http://www.sas.com/en_us/software/viya.html) 6 | platform. 7 | Using the SWAT package, you can write an R program that connects to a CAS server, 8 | analyze large in-memory data sets, and then work with the results of the data 9 | analysis using familiar data-wrangling techniques in R. 10 | 11 | This package provides facilities for starting a CAS session and 12 | running actions in CAS--such as classifying data with a decision tree or modeling 13 | with linear regression. Data processing is performed by CAS, which can scale from 14 | a single-machine server to distributed servers that run on multiple hosts and 15 | perform massively parallel processing. 16 | 17 | ## Installation and Configuration 18 | 19 | ### Requirements 20 | 21 | To use the SWAT package for R, the client machine that runs R must meet 22 | the following requirements: 23 | 24 | * Use 64-bit Linux or 64-bit Windows. 25 | * Use a 64-bit version of R. 26 | * Use R 3.1.0 or later. 27 | * Install the ``dplyr``, ``httr`` and ``jsonlite`` packages. These packages 28 | have additional dependencies that are automatically installed from CRAN 29 | when you run install.packages(). 30 | 31 | ### Installation 32 | 33 | The SWAT package for R is available from SAS as a tar.gz file. You can download 34 | releases from https://github.com/sassoftware/R-swat/releases. 35 | 36 | After you download the package, you can install the package with a command that is 37 | similar to the following: 38 | 39 | ``` 40 | R CMD INSTALL R-swat-X.X.X-platform.tar.gz 41 | ``` 42 | 43 | You can also install from within R directly using a URL. 44 | 45 | ``` 46 | # Make sure prerequisites are installed 47 | > install.packages('dplyr') 48 | > install.packages('httr') 49 | > install.packages('jsonlite') 50 | 51 | > install.packages('https://github.com/sassoftware/R-swat/releases/download/vX.X.X/R-swat-X.X.X-platform.tar.gz', 52 | repos=NULL, type='file') 53 | ``` 54 | 55 | If you are running on a platform that does not have an associated installer, 56 | you should install the source code tar.gz. These platforms will be 57 | limited to using the CAS REST interface only. 58 | 59 | ``` 60 | > install.packages('https://github.com/sassoftware/R-swat/archive/vX.X.X.tar.gz', 61 | repos=NULL, type='file') 62 | ``` 63 | 64 | ## Connecting to CAS 65 | 66 | ### Authinfo File 67 | Using a .authinfo file is not required to use the package, but is recommended. When you 68 | enter your credentials (user ID and password) in a .authinfo file and secure the 69 | permissions, you can avoid specifying those credentials in programs. 70 | 71 | Throughout the documentation, it is assumed that you have a .authinfo file. The following 72 | statement connects R to CAS and supplies the credentials from the .authinfo file: 73 | 74 | ``` 75 | conn <- swat::CAS('cloud.example.com', 8777, protocol='http') 76 | ``` 77 | 78 | If you do not use a .authinfo file, then you must connect with a statement like the following: 79 | 80 | ``` 81 | conn <- swat::CAS('cloud.example.com', 8777, protocol='http', username='sasdemo', password='!s3cret') 82 | ``` 83 | 84 | ### Binary and REST Communication 85 | 86 | Communication between R and CAS can be performed in a binary format with proprietary C 87 | libraries, or over HTTP to a REST interface on the server. The C libraries (and therefore 88 | binary communication) are supported for 64-bit Linux or Windows only. Connections to CAS that use 89 | binary communication are similar to the following example: 90 | 91 | ``` 92 | conn <- swat::CAS('cloud.example.com', 5570) 93 | ``` 94 | 95 | ## Example 96 | 97 | ``` 98 | > library(swat) 99 | 100 | # Connect to CAS 101 | > conn <- swat::CAS('cloud.example.com', 8777) 102 | 103 | # Load Iris data set into in-memory table 104 | > iris.ct <- as.casTable(conn, iris) 105 | 106 | # Use basic R functions on CAS table 107 | > min(iris.ct$Sepal.Length) 108 | [1] 4.3 109 | 110 | > max(iris.ct$Sepal.Length) 111 | [1] 7.9 112 | 113 | > mean(iris.ct$Sepal.Length) 114 | [1] 5.843333 115 | 116 | # Call CAS actions on the table 117 | > out <- cas.simple.summary(iris.ct) 118 | > out 119 | $Summary 120 | Column Min Max N NMiss Mean Sum Std StdErr Var 121 | 1 Sepal.Length 4.3 7.9 150 0 5.843333 876.5 0.8280661 0.06761132 0.6856935 122 | 2 Sepal.Width 2.0 4.4 150 0 3.057333 458.6 0.4358663 0.03558833 0.1899794 123 | 3 Petal.Length 1.0 6.9 150 0 3.758000 563.7 1.7652982 0.14413600 3.1162779 124 | 4 Petal.Width 0.1 2.5 150 0 1.199333 179.9 0.7622377 0.06223645 0.5810063 125 | USS CSS CV TValue ProbT 126 | 1 5223.85 102.16833 14.17113 86.42537 3.331256e-129 127 | 2 1430.40 28.30693 14.25642 85.90830 8.004458e-129 128 | 3 2582.71 464.32540 46.97441 26.07260 2.166017e-57 129 | 4 302.33 86.56993 63.55511 19.27060 2.659021e-42 130 | 131 | # Explore results 132 | > out$Summary[c('Column', 'Min', 'Max')] 133 | ``` 134 | 135 | If you get an error message about the **TCP/IP negClientSSL support routine**, you 136 | likely have an issue with your SSL certificate configuration. See the 137 | [Encryption](https://sassoftware.github.io/python-swat/encryption.html) documentation 138 | (the R configuration is the same as the Python client) for more information. 139 | -------------------------------------------------------------------------------- /SUPPORT.md: -------------------------------------------------------------------------------- 1 | ## Support 2 | 3 | We use GitHub for tracking bugs and feature requests. Please submit a GitHub issue or pull request for support. 4 | -------------------------------------------------------------------------------- /cicd/get-basename.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | ''' 4 | Return the basename for the package 5 | 6 | If no release is specified, only the short version of the basename is returned. 7 | 8 | R-swat-{version} 9 | 10 | If a release is specified, the complete basename is returned. If no platform is 11 | specified, the platform the program is running on is used. 12 | 13 | R-swat-{version}+{release}-{platform} 14 | 15 | ''' 16 | 17 | import argparse 18 | import glob 19 | import os 20 | import platform 21 | import re 22 | import sys 23 | 24 | 25 | def get_platform(): 26 | ''' Return the Anaconda platform name for the current platform ''' 27 | plat = platform.system().lower() 28 | if 'darwin' in plat: 29 | return 'osx-64' 30 | if plat.startswith('win'): 31 | return 'win-64' 32 | if 'linux' in plat: 33 | machine = platform.machine().lower() 34 | if 'x86' in machine: 35 | return 'linux-64' 36 | if 'ppc' in machine: 37 | return 'linux-ppc64le' 38 | return 'unknown' 39 | 40 | 41 | def print_err(*args, **kwargs): 42 | ''' Print a message to stderr ''' 43 | sys.stderr.write(*args, **kwargs) 44 | sys.stderr.write('\n') 45 | 46 | 47 | def main(args): 48 | ''' Main routine ''' 49 | 50 | version = None 51 | tk_version = None 52 | 53 | init = glob.glob(os.path.join(args.root, 'DESCRIPTION'))[0] 54 | with open(init, 'r') as init_in: 55 | for line in init_in: 56 | m = re.search(r'''^Version\s*:\s*(\S+)''', line) 57 | if m: 58 | version = m.group(1) 59 | 60 | m = re.search(r'''^TKVersion\s*:\s*(\S+)''', line) 61 | if m: 62 | tk_version = m.group(1) 63 | if tk_version == 'none': 64 | tk_version = 'REST-only' 65 | 66 | if version: 67 | if args.full: 68 | print('R-swat-{}+{}-{}'.format(version, tk_version, args.platform)) 69 | else: 70 | print('R-swat-{}'.format(version)) 71 | return 0 72 | 73 | print_err('ERROR: Could not find DESCRIPTION file.') 74 | 75 | return 1 76 | 77 | 78 | if __name__ == '__main__': 79 | parser = argparse.ArgumentParser(description=__doc__.strip(), 80 | formatter_class=argparse.RawTextHelpFormatter) 81 | 82 | parser.add_argument('root', type=str, metavar='', nargs='?', default='.', 83 | help='root directory of R package') 84 | 85 | parser.add_argument('--platform', '-p', type=str, metavar='', 86 | choices=['linux-64', 'osx-64', 'win-64', 'linux-ppc64le'], 87 | default=get_platform(), 88 | help='platform of the resulting package') 89 | parser.add_argument('--full', '-f', action='store_true', 90 | help='return the full variant of the basename ' 91 | 'including TK version and platform') 92 | 93 | args = parser.parse_args() 94 | 95 | sys.exit(main(args) or 0) 96 | -------------------------------------------------------------------------------- /cicd/get-host.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | ''' 4 | Return a random hostname from the specified collection of names 5 | 6 | This utility is used to randomly choose a hostname from a list 7 | or names with a numeric range. It allows you to put bracketed 8 | lists or ranges of values in one or more places in the hostname 9 | to enumerate the possibilities. For example, if you had test 10 | machines named `test01`, `test02`, and `test03`. You could 11 | retrieve a random item from this list with the following call: 12 | 13 | get-host.py 'test[01,02,03]' 14 | 15 | This would return one of the following: 16 | 17 | test01 18 | test02 19 | test03 20 | 21 | You can also specify numeric ranges: 22 | 23 | get-host.py 'test[01-03]' 24 | 25 | Which would return one of the above results as well. 26 | 27 | ''' 28 | 29 | import argparse 30 | import itertools 31 | import os 32 | import random 33 | import re 34 | import sys 35 | 36 | 37 | def main(args): 38 | ''' Main routine ''' 39 | out = [] 40 | for arg in args.host_expr: 41 | parts = [x for x in re.split(r'(?:\[|\])', arg) if x] 42 | 43 | for i, part in enumerate(parts): 44 | if ',' in part: 45 | parts[i] = re.split(r'\s*,\s*', part) 46 | elif re.match(r'^\d+\-\d+$', part): 47 | start, end = part.split('-') 48 | width = len(start) 49 | start = int(start) 50 | end = int(end) 51 | parts[i] = [('%%0%sd' % width) % x for x in range(start, end + 1)] 52 | else: 53 | parts[i] = [part] 54 | 55 | out += list(''.join(x) for x in itertools.product(*parts)) 56 | 57 | print(random.choice(out)) 58 | 59 | 60 | if __name__ == '__main__': 61 | parser = argparse.ArgumentParser(description=__doc__.strip(), 62 | formatter_class=argparse.RawTextHelpFormatter) 63 | 64 | parser.add_argument('host_expr', type=str, metavar='hostname-expr', nargs='+', 65 | help='hostname expression (ex. myhost[01-06].com)') 66 | 67 | args = parser.parse_args() 68 | 69 | main(args) 70 | -------------------------------------------------------------------------------- /cicd/get-protocol.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | ''' 4 | Return the preferred CAS protocol ('cas' if TK is available; 'http' otherwise) 5 | 6 | This utility checks the package `DESCRIPTION` file for a `TKVersion` 7 | parameter that indicates the packaged version of the TK libraries. 8 | If it finds it, the `cas` protocol will be returned. If the value is 9 | set to `None`, the `http` protocol is returned. 10 | 11 | ''' 12 | 13 | import argparse 14 | import glob 15 | import os 16 | import re 17 | import sys 18 | 19 | 20 | def main(args): 21 | ''' Main routine ''' 22 | version = None 23 | 24 | init = glob.glob(os.path.join(args.root, 'DESCRIPTION'))[0] 25 | with open(init, 'r') as init_in: 26 | for line in init_in: 27 | m = re.match(r'''TKVersion\s*:\s*(\S+)''', line) 28 | if m: 29 | version = m.group(1) 30 | if version == 'none': 31 | version = None 32 | break 33 | 34 | print(version and 'cas' or 'http') 35 | 36 | 37 | if __name__ == '__main__': 38 | parser = argparse.ArgumentParser(description=__doc__.strip()) 39 | 40 | parser.add_argument('root', type=str, metavar='', 41 | default='.', nargs='?', 42 | help='root directory of R package') 43 | 44 | args = parser.parse_args() 45 | 46 | sys.exit(main(args) or 0) 47 | -------------------------------------------------------------------------------- /cicd/get-server-info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | ''' 4 | Retrieve CAS server information from CAS log 5 | 6 | The CAS server command is expected to have a `-display` option with a unique 7 | key for the invoked server. This is used to retrieve the PID of the server 8 | process. The basename of the CAS log file must match the value in the 9 | `-display` option. 10 | 11 | ''' 12 | 13 | import argparse 14 | import os 15 | import re 16 | import subprocess 17 | import sys 18 | import time 19 | 20 | 21 | def print_err(*args, **kwargs): 22 | ''' Print a message to stderr ''' 23 | sys.stderr.write(*args, **kwargs) 24 | sys.stderr.write('\n') 25 | 26 | 27 | def main(args): 28 | ''' 29 | Main routine 30 | 31 | Parameters 32 | ---------- 33 | args : argparse arguments 34 | Arguments to the command-line 35 | 36 | ''' 37 | if not os.path.isfile(args.log_file): 38 | print_err('ERROR: File not found: {}'.format(args.log_file)) 39 | sys.exit(1) 40 | 41 | iters = 0 42 | for i in range(args.retries): 43 | iters += 1 44 | time.sleep(args.interval) 45 | if iters > args.retries: 46 | print_err('ERROR: Could not locate CAS log file.') 47 | sys.exit(1) 48 | 49 | with open(args.log_file, 'r') as logf: 50 | txt = logf.read() 51 | m = re.search(r'===\s+.+?(\S+):(\d+)\s+.+?\s+.+?:(\d+)\s+===', txt) 52 | if m: 53 | hostname = m.group(1) 54 | binary_port = m.group(2) 55 | http_port = m.group(3) 56 | 57 | sys.stdout.write('CASHOST={} '.format(hostname)) 58 | sys.stdout.write('CAS_HOST={} '.format(hostname)) 59 | sys.stdout.write('CAS_BINARY_PORT={} '.format(binary_port)) 60 | sys.stdout.write('CAS_HTTP_PORT={} '.format(http_port)) 61 | sys.stdout.write('CAS_BINARY_URL=cas://{}:{} '.format(hostname, 62 | binary_port)) 63 | sys.stdout.write('CAS_HTTP_URL=http://{}:{} '.format(hostname, 64 | http_port)) 65 | 66 | if 'CASPROTOCOL' in os.environ or 'CAS_PROTOCOL' in os.environ: 67 | protocol = os.environ.get('CASPROTOCOL', 68 | os.environ.get('CAS_PROTOCOL', 'http')) 69 | if protocol == 'cas': 70 | sys.stdout.write('CASPROTOCOL=cas ') 71 | sys.stdout.write('CAS_PROTOCOL=cas ') 72 | sys.stdout.write('CASPORT={} '.format(binary_port)) 73 | sys.stdout.write('CAS_PORT={} '.format(binary_port)) 74 | sys.stdout.write('CASURL=cas://{}:{} '.format(hostname, 75 | binary_port)) 76 | sys.stdout.write('CAS_URL=cas://{}:{} '.format(hostname, 77 | binary_port)) 78 | else: 79 | sys.stdout.write('CASPROTOCOL={} '.format(protocol)) 80 | sys.stdout.write('CAS_PROTOCOL={} '.format(protocol)) 81 | sys.stdout.write('CASPORT={} '.format(http_port)) 82 | sys.stdout.write('CAS_PORT={} '.format(http_port)) 83 | sys.stdout.write('CASURL={}://{}:{} '.format(protocol, hostname, 84 | http_port)) 85 | sys.stdout.write('CAS_URL={}://{}:{} '.format(protocol, hostname, 86 | http_port)) 87 | 88 | elif 'REQUIRES_TK' in os.environ: 89 | if os.environ.get('REQUIRES_TK', '') == 'true': 90 | sys.stdout.write('CASPROTOCOL=cas ') 91 | sys.stdout.write('CAS_PROTOCOL=cas ') 92 | sys.stdout.write('CASPORT={} '.format(binary_port)) 93 | sys.stdout.write('CAS_PORT={} '.format(binary_port)) 94 | sys.stdout.write('CASURL=cas://{}:{} '.format(hostname, 95 | binary_port)) 96 | sys.stdout.write('CAS_URL=cas://{}:{} '.format(hostname, 97 | binary_port)) 98 | else: 99 | sys.stdout.write('CASPROTOCOL=http ') 100 | sys.stdout.write('CAS_PROTOCOL=http ') 101 | sys.stdout.write('CASPORT={} '.format(http_port)) 102 | sys.stdout.write('CAS_PORT={} '.format(http_port)) 103 | sys.stdout.write('CASURL=http://{}:{} '.format(hostname, 104 | http_port)) 105 | sys.stdout.write('CAS_URL=http://{}:{} '.format(hostname, 106 | http_port)) 107 | 108 | # Get CAS server pid 109 | cmd = ('ssh -x -o StrictHostKeyChecking=no ' 110 | '-o UserKnownHostsFile=/dev/null {} ' 111 | 'ps ax | grep {} | grep -v grep | head -1' 112 | ).format(hostname, '.'.join(args.log_file.split('.')[:-1])) 113 | pid = subprocess.check_output(cmd, shell=True) \ 114 | .decode('utf-8').strip().split(' ', 1)[0] 115 | sys.stdout.write('CAS_PID={} '.format(pid)) 116 | 117 | # Write pid file 118 | if args.pid_file: 119 | with open(args.pid_file, 'w') as pid_file_out: 120 | pid_file_out.write(pid) 121 | 122 | break 123 | 124 | 125 | if __name__ == '__main__': 126 | 127 | opts = argparse.ArgumentParser(description=__doc__.strip(), 128 | formatter_class=argparse.RawTextHelpFormatter) 129 | 130 | opts.add_argument('log_file', type=str, metavar='log-file', 131 | help='path to CAS server log') 132 | 133 | opts.add_argument('--login-name', '-l', type=str, metavar='name', 134 | help='login name for ssh when acquiring CAS pid') 135 | opts.add_argument('--pid-file', '-p', type=str, metavar='filename', 136 | help='file to write CAS pid to') 137 | opts.add_argument('--retries', '-r', default=5, type=int, metavar='#', 138 | help='number of retries in attempting to locate the log file') 139 | opts.add_argument('--interval', '-i', default=3, type=int, metavar='#', 140 | help='number of seconds between each retry') 141 | 142 | args = opts.parse_args() 143 | 144 | main(args) 145 | -------------------------------------------------------------------------------- /cicd/get-version.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | ''' 4 | Return the version of the package 5 | 6 | This command looks for the `Version` attribute in the `DESCRIPTION` 7 | file to determine the package version. 8 | 9 | ''' 10 | 11 | from __future__ import print_function, division, absolute_import, unicode_literals 12 | 13 | import argparse 14 | import glob 15 | import os 16 | import re 17 | import sys 18 | 19 | 20 | def print_err(*args, **kwargs): 21 | ''' Print a message to stderr ''' 22 | sys.stderr.write(*args, **kwargs) 23 | sys.stderr.write('\n') 24 | 25 | 26 | def main(args): 27 | ''' Main routine ''' 28 | 29 | version = None 30 | 31 | init = glob.glob(os.path.join(args.root, 'DESCRIPTION'))[0] 32 | with open(init, 'r') as init_in: 33 | for line in init_in: 34 | m = re.search(r'''^Version\s*:\s*(\S+)''', line) 35 | if m: 36 | version = m.group(1) 37 | 38 | if version: 39 | if args.as_expr: 40 | print('=={}'.format(version)) 41 | else: 42 | print(version) 43 | return 44 | 45 | print_err('ERROR: Could not find DESCRIPTION file.') 46 | 47 | return 1 48 | 49 | 50 | if __name__ == '__main__': 51 | parser = argparse.ArgumentParser(description=__doc__.strip(), 52 | formatter_class=argparse.RawTextHelpFormatter) 53 | 54 | parser.add_argument('root', type=str, metavar='', nargs='?', 55 | default='.', help='root directory of R package') 56 | 57 | parser.add_argument('-e', '--as-expr', action='store_true', 58 | help='format the version as a dependency expression') 59 | 60 | args = parser.parse_args() 61 | 62 | sys.exit(main(args) or 0) 63 | -------------------------------------------------------------------------------- /cicd/get-workspace-url.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | ''' 4 | Return the WORKSPACE as a URL 5 | 6 | Some downstream commands require the path to a Jenkins `WORKSPACE` variable 7 | as a URL rather than a file path. This URL must be formatted differently for 8 | Windows than for UNIX-like operating systems. This utility does the proper 9 | formatting for the host type. 10 | 11 | ''' 12 | 13 | import argparse 14 | import itertools 15 | import os 16 | import re 17 | import sys 18 | 19 | 20 | def main(args): 21 | ''' Main routine ''' 22 | cwd = os.getcwd() 23 | 24 | if sys.platform.lower().startswith('win'): 25 | workspace_url = 'file:///{}'.format(re.sub(r'^(/[A-Za-z])/', '\1:/', 26 | cwd.replace('\\', '/'))) 27 | else: 28 | workspace_url = 'file://{}'.format(cwd) 29 | 30 | print(workspace_url) 31 | 32 | 33 | if __name__ == '__main__': 34 | parser = argparse.ArgumentParser(description=__doc__.strip(), 35 | formatter_class=argparse.RawTextHelpFormatter) 36 | 37 | args = parser.parse_args() 38 | 39 | main(args) 40 | -------------------------------------------------------------------------------- /cicd/promote-release-candidate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | ''' 4 | Utitily for moving a release candidate to a full release 5 | 6 | When a Github release is first created, it is done as a draft release. 7 | This is done so that the release can be tested and verified before going 8 | public as an official release. This utility is used to promote a 9 | draft release to a public release. 10 | 11 | ''' 12 | 13 | import argparse 14 | import datetime 15 | import glob 16 | import io 17 | import os 18 | import re 19 | import requests 20 | import shutil 21 | import sys 22 | import subprocess 23 | import tarfile 24 | import tempfile 25 | from urllib.parse import quote 26 | from urllib.request import urlopen, urlretrieve 27 | 28 | 29 | GITHUB_TOKEN = os.environ['GITHUB_TOKEN'] 30 | 31 | 32 | def get_repo(): 33 | ''' Retrieve the repo part of the git URL ''' 34 | cmd = ['git', 'remote', 'get-url', 'origin'] 35 | repo = subprocess.check_output(cmd).decode('utf-8').strip() 36 | repo = re.search(r'github.com[/:](.+?)\.git$', repo).group(1) 37 | return repo 38 | 39 | 40 | def create_release(tag_name, target_commitish, rc_release): 41 | ''' 42 | Create new release on Github 43 | 44 | POST /repos/:owner/:repo/releases 45 | 46 | ''' 47 | res = requests.post( 48 | 'https://api.github.com/repos/{}/releases'.format(get_repo()), 49 | headers=dict(Authorization='token {}'.format(GITHUB_TOKEN), 50 | Accept='application/vnd.github.v3+json'), 51 | json=dict(tag_name=tag_name, 52 | target_commitish=target_commitish, 53 | name=re.sub(r'(v\d+\.\d+\.\d+)-rc', r'\1', rc_release['name']), 54 | body=re.sub(r'(v\d+\.\d+\.\d+)-rc', r'\1', rc_release['body']), 55 | draft=False, prerelease=False) 56 | ) 57 | 58 | if res.status_code >= 400: 59 | raise RuntimeError(res.json()) 60 | 61 | res = res.json() 62 | 63 | copy_assets(res['upload_url'].split('{')[0], rc_release['assets']) 64 | 65 | 66 | def copy_assets(url, assets): 67 | ''' Copy assets from other release to the upload url ''' 68 | for asset in assets: 69 | asset_url = asset['browser_download_url'] 70 | print(' > {}'.format(asset['name'])) 71 | with urlopen(asset_url) as asset_file: 72 | requests.post( 73 | '{}?name={}'.format(url, quote(asset['name'])), 74 | headers={'Authorization': 'token {}'.format(GITHUB_TOKEN), 75 | 'Accept': 'application/vnd.github.v3+json', 76 | 'Content-Type': 'application/octet-stream'}, 77 | data=asset_file.read() 78 | ) 79 | 80 | 81 | def git_tag(tag, sha=None): 82 | ''' Add a tag ''' 83 | cmd = ['git', 'tag', tag] 84 | if sha: 85 | cmd.append(sha) 86 | subprocess.check_call(cmd) 87 | 88 | 89 | def git_push(tag=None): 90 | ''' Push updates ''' 91 | cmd = ['git', 'push'] 92 | subprocess.check_call(cmd) 93 | if tag: 94 | cmd = ['git', 'push', 'origin', tag] 95 | subprocess.check_call(cmd) 96 | 97 | 98 | def git_fetch(): 99 | ''' Make sure we have all commits and tags ''' 100 | cmd = ['git', 'fetch', '--tags'] 101 | subprocess.check_call(cmd) 102 | 103 | 104 | def delete_release(tag_name): 105 | ''' Remove local and remote tags for the given release ''' 106 | # Delete release 107 | res = requests.get( 108 | 'https://api.github.com/repos/{}/releases/tags/{}'.format(get_repo(), tag_name), 109 | headers=dict(Authorization='token {}'.format(GITHUB_TOKEN), 110 | Accept='application/vnd.github.v3+json')) 111 | 112 | if res.status_code < 400: 113 | release_url = res.json()['url'] 114 | res = requests.delete( 115 | release_url, 116 | headers=dict(Authorization='token {}'.format(GITHUB_TOKEN), 117 | Accept='application/vnd.github.v3+json')) 118 | 119 | # Delete tags 120 | del_tags = [tag_name, tag_name.replace('-rc', '-snapshot')] 121 | cmd = ['git', 'show-ref', '--tags'] 122 | for line in subprocess.check_output(cmd).decode('utf-8').strip().split('\n'): 123 | sha, tag = re.split(r'\s+', line.strip()) 124 | tag = tag.split('/')[-1] 125 | if tag in del_tags: 126 | cmd = ['git', 'tag', '-d', tag] 127 | subprocess.check_call(cmd) 128 | cmd = ['git', 'push', 'origin', ':refs/tags/{}'.format(tag)] 129 | subprocess.check_call(cmd) 130 | break 131 | 132 | 133 | def checkout_main(tag=None): 134 | ''' Make sure we're on the main branch ''' 135 | cmd = ['git', 'checkout', 'main'] 136 | subprocess.check_call(cmd) 137 | 138 | 139 | def get_release(tag_name): 140 | ''' Retrieve the upload URL for the given tag ''' 141 | res = requests.get( 142 | 'https://api.github.com/repos/{}/releases/tags/{}'.format(get_repo(), tag_name), 143 | headers=dict(Authorization='token {}'.format(GITHUB_TOKEN), 144 | Accept='application/vnd.github.v3+json')) 145 | 146 | if res.status_code < 400: 147 | return res.json() 148 | 149 | raise RuntimeError('Could not locate tag name: {}'.format(tag_name)) 150 | 151 | 152 | def get_release_sha(tag_name): 153 | ''' Get the sha of the tag ''' 154 | cmd = ['git', 'rev-list', '-n', '1', tag_name] 155 | return subprocess.check_output(cmd).decode('utf-8').strip() 156 | 157 | 158 | def tag_type(value): 159 | ''' Check version syntax ''' 160 | if re.match(r'^v\d+\.\d+\.\d+-rc$', value): 161 | return value 162 | raise argparse.ArgumentTypeError(value) 163 | 164 | 165 | def main(args): 166 | ''' Main routine ''' 167 | # Make sure local repo is up-to-date 168 | git_fetch() 169 | checkout_main() 170 | 171 | release_tag = args.tag.replace('-rc', '') 172 | release_sha = get_release_sha(args.tag) 173 | 174 | # Retrieve rc release info 175 | rc_release = get_release(args.tag) 176 | 177 | # Push release 178 | git_tag(release_tag, sha=release_sha) 179 | git_push(tag=release_tag) 180 | create_release(release_tag, release_sha, rc_release) 181 | 182 | # Delete rc release and snapshots 183 | delete_release(args.tag) 184 | delete_release(args.tag.replace('-rc', '-snapshot')) 185 | 186 | return 0 187 | 188 | 189 | if __name__ == '__main__': 190 | parser = argparse.ArgumentParser(description=__doc__.strip(), 191 | formatter_class=argparse.RawTextHelpFormatter) 192 | 193 | parser.add_argument('tag', type=tag_type, metavar='tag', 194 | help='tag of the release to promote') 195 | 196 | args = parser.parse_args() 197 | 198 | try: 199 | sys.exit(main(args)) 200 | except KeyboardInterrupt: 201 | sys.exit(1) 202 | -------------------------------------------------------------------------------- /cicd/upload-assests.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | ''' 4 | Upload assets to a given Github release 5 | 6 | This utility uploads a set of assets to an existing Github release 7 | which is specified by the tag for that release. 8 | 9 | ''' 10 | 11 | import argparse 12 | import glob 13 | import os 14 | import re 15 | import requests 16 | import shutil 17 | import subprocess 18 | import sys 19 | import tarfile 20 | from urllib.parse import quote 21 | 22 | 23 | if '--help' not in sys.argv and '-h' not in sys.argv: 24 | try: 25 | GITHUB_TOKEN = os.environ['GITHUB_TOKEN'] 26 | except KeyError: 27 | sys.stderr.write('ERROR: This utility requires a Github ' 28 | 'token for accessing the Github release API.\n') 29 | sys.stderr.write(' The variable should be held in an ' 30 | 'environment variable named GITHUB_TOKEN.\n') 31 | sys.exit(1) 32 | 33 | 34 | def print_err(*args, **kwargs): 35 | ''' Print a message to stderr ''' 36 | sys.stderr.write(*args, **kwargs) 37 | sys.stderr.write('\n') 38 | 39 | 40 | def get_repo(): 41 | ''' Retrieve the repo part of the git URL ''' 42 | cmd = ['git', 'remote', 'get-url', 'origin'] 43 | repo = subprocess.check_output(cmd).decode('utf-8').strip() 44 | repo = re.search(r'github.com/(.+?)\.git$', repo).group(1) 45 | return repo 46 | 47 | 48 | def get_release(tag_name): 49 | ''' Retrieve the upload URL for the given tag ''' 50 | res = requests.get( 51 | 'https://api.github.com/repos/{}/releases/tags/{}'.format(get_repo(), tag_name), 52 | headers=dict(Authorization='token {}'.format(GITHUB_TOKEN), 53 | Accept='application/vnd.github.v3+json')) 54 | 55 | if res.status_code < 400: 56 | return res.json() 57 | 58 | raise RuntimeError('Could not locate tag name: {}'.format(tag_name)) 59 | 60 | 61 | def upload_asset(url, filename): 62 | ''' 63 | Upload an asset to a release 64 | 65 | POST :server/repos/:owner/:repo/releases/:release_id/assets?name=:asset_filename 66 | 67 | ''' 68 | upload_url = url + '?name={}'.format(quote(os.path.split(filename)[-1])) 69 | with open(filename, 'rb') as asset_file: 70 | requests.post( 71 | upload_url, 72 | headers={'Authorization': 'token {}'.format(GITHUB_TOKEN), 73 | 'Accept': 'application/vnd.github.v3+json', 74 | 'Content-Type': 'application/octet-stream'}, 75 | data=asset_file 76 | ) 77 | 78 | 79 | def delete_asset(asset_id): 80 | ''' Delete the resource at the given ID ''' 81 | requests.delete( 82 | 'https://api.github.com/repos/{}/releases/assets/{}'.format(get_repo(), asset_id), 83 | headers=dict(Authorization='token {}'.format(GITHUB_TOKEN), 84 | Accept='application/vnd.github.v3+json'), 85 | json=dict(asset_id=asset_id)) 86 | 87 | 88 | def main(args): 89 | ''' Main routine ''' 90 | release = get_release(args.tag) 91 | 92 | upload_url = release['upload_url'].split('{')[0] 93 | assets = {x['name']: x for x in release['assets']} 94 | 95 | for asset in args.assets: 96 | print(asset) 97 | filename = os.path.split(asset)[-1] 98 | if filename in assets: 99 | if args.force: 100 | delete_asset(assets[filename]['id']) 101 | else: 102 | print_err('WARNING: Asset already exists: {}'.format(asset)) 103 | continue 104 | upload_asset(upload_url, asset) 105 | 106 | return 0 107 | 108 | 109 | if __name__ == '__main__': 110 | parser = argparse.ArgumentParser(description=__doc__.strip(), 111 | formatter_class=argparse.RawTextHelpFormatter) 112 | 113 | parser.add_argument('--tag', '-t', type=str, metavar='tag_name', required=True, 114 | help='tag of release to upload the asset to') 115 | parser.add_argument('--force', '-f', action='store_true', 116 | help='force upload even if asset of the same name exists') 117 | parser.add_argument('assets', type=str, metavar='filename', nargs='+', 118 | help='assets to upload') 119 | 120 | args = parser.parse_args() 121 | 122 | try: 123 | sys.exit(main(args)) 124 | except argparse.ArgumentTypeError as exc: 125 | print_err('ERROR: {}'.format(exc)) 126 | sys.exit(1) 127 | except KeyboardInterrupt: 128 | sys.exit(1) 129 | -------------------------------------------------------------------------------- /conda.recipe/meta.yaml: -------------------------------------------------------------------------------- 1 | {% set name = 'R-swat' %} 2 | {% set version = '1.4.1' %} 3 | {% set build = '0' %} 4 | 5 | # linux64 : r - 3.4.3, 3.5.0, 3.6.0 6 | # : mro - 3.4.3, 3.5.0, 3.5.1 7 | # osx : r - 3.4.3, 3.5.0, 3.5.1, 3.6.0 8 | # win64 : r - 3.4.3, 3.5.1, 3.6.0 9 | # : mro - 3.4.3, 3.5.1 10 | 11 | {% set r_base = 'mro-base' %} 12 | {% set r_version = '3.6.0' %} 13 | 14 | package: 15 | name: {{ name|lower() }} 16 | version: {{ version|replace("-", "_") }} 17 | 18 | source: 19 | url: https://github.com/sassoftware/{{ name }}/releases/download/v{{ version }}/{{ name }}-{{ version }}-linux64.tar.gz # [linux64] 20 | url: https://github.com/sassoftware/{{ name }}/releases/download/v{{ version }}/{{ name }}-{{ version }}-linux-ppc64le.tar.gz # [ppc64le] 21 | url: https://github.com/sassoftware/{{ name }}/releases/download/v{{ version }}/{{ name }}-{{ version }}-win64.tar.gz # [win64] 22 | url: https://github.com/sassoftware/{{ name }}/archive/v{{ version }}.tar.gz # [not linux64 and not win64 and not ppc64le] 23 | 24 | build: 25 | number: {{ build }} 26 | build: False 27 | script: R CMD INSTALL --build --install-tests . # [not win] 28 | script: "\"%R%\" CMD INSTALL --build --install-tests \"%SRC_DIR%\"" # [win] 29 | binary_relocation: False 30 | missing_dso_whitelist: 31 | - /lib/libpthread.so.0 32 | - /lib/libm.so.6 33 | - /lib/libc.so.6 34 | - /lib/libdl.so.2 35 | - /lib/libcrypt.so.1 36 | - /lib/librt.so.1 37 | - /lib/libresolv.so.2 38 | - /lib/libgcc_s.so.1 39 | - /lib/libstdc++.so.6 40 | - /lib/libXt.so.6 # begin xorgpkg.so 41 | - /lib/libXmu.so.6 # 42 | - /lib/libSM.so.6 # 43 | - /lib/libXext.so.6 # 44 | - /lib/libjpeg.so.62 # 45 | - /lib/libICE.so.6 # 46 | - /lib/libfontconfig.so.1 # 47 | - /lib/libXft.so.2 # 48 | - /lib/libpng12.so.0 # 49 | - /lib/libX11.so.6 # end xorgpkg.so 50 | - libdfschr-1.4.so 51 | - libdfssys-1.3.so 52 | - libdfsfio-1.5.so 53 | - libdflic-1.4.so 54 | - libjsig.so 55 | - libjvm.so 56 | - /lib/libgssapi_krb5.so.2 57 | - /lib/libkrb5.so.3 58 | - /lib/libuuid.so.1 59 | - /lib64/libnuma.so.1 60 | 61 | requirements: 62 | build: 63 | - {{ r_base }} ={{ r_version }} 64 | - r-httr 65 | - r-jsonlite 66 | - r-codetools 67 | run: 68 | - {{ r_base }} 69 | - r-httr 70 | - r-jsonlite 71 | - libnuma # [linux64] 72 | - libuuid # [linux64] 73 | - krb5 # [linux64] 74 | 75 | test: 76 | requires: 77 | - {{ r_base }} ={{ r_version }} 78 | - r-devtools 79 | - r-testthat 80 | # - r-xlsx 81 | # - r-jpeg 82 | - r-xml2 83 | commands: 84 | - R -f "${RECIPE_DIR}/test_package.R" # [not win] 85 | - "\"%R%\" -f \"%RECIPE_DIR%\\test_package.R\"" # [win] 86 | 87 | about: 88 | home: https://github.com/sassoftware/R-swat 89 | license: Apache 2.0 + SAS Additional Functionality 90 | license_file: LICENSE 91 | summary: SAS Viya R Client 92 | dev_url: https://github.com/sassoftware/R-swat 93 | -------------------------------------------------------------------------------- /conda.recipe/test_package.R: -------------------------------------------------------------------------------- 1 | junit_xml <- paste(Sys.getenv("TEST_REPORT_DIR"), 2 | Sys.getenv("R_BASE"), "-", Sys.getenv("R_VERSION"), 3 | "-junit.xml", sep="") 4 | test_dir <- system.file("tests", "testthat", package = "swat") 5 | 6 | testthat::test_dir(test_dir, stop_on_failure=TRUE) #, 7 | #reporter=testthat::JunitReporter$new(file=junit_xml)) 8 | -------------------------------------------------------------------------------- /inst/icons/sas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/R-swat/847881dad284574ba3438b39db68a17b42e5d09e/inst/icons/sas.png -------------------------------------------------------------------------------- /inst/rstudio/connections.dcf: -------------------------------------------------------------------------------- 1 | Name: CAS 2 | HelpUrl: https://go.documentation.sas.com/doc/en/pgmsascdc/default/caspg3r/titlepage.htm 3 | Icon: icons/sas.png 4 | -------------------------------------------------------------------------------- /inst/rstudio/connections/CAS.R: -------------------------------------------------------------------------------- 1 | library(swat) 2 | conn <- CAS("${1:CAS URL=https$colon$//server$colon$port/cas-shared-default-http/}", authinfo = "${2:Authinfo Path}") 3 | -------------------------------------------------------------------------------- /man/CAS-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/swat.R 3 | \docType{class} 4 | \name{CAS-class} 5 | \alias{CAS-class} 6 | \alias{CAS} 7 | \title{CAS Object Class} 8 | \arguments{ 9 | \item{hostname}{A \code{character} string that specifies the 10 | host name of the CAS controller.} 11 | 12 | \item{port}{A \code{numeric} value that specifies the network 13 | port number that the CAS controller listens on.} 14 | 15 | \item{protocol}{A \code{string} that specifies one of the following: 16 | \describe{ 17 | \item{cas}{use binary communication. This is the default.} 18 | \item{http}{use HTTP communication with the REST interface 19 | on the CAS controller.} 20 | \item{https}{use HTTPS communication with the REST interface 21 | on the CAS controller. This protocol must be specified 22 | explicity.} 23 | \item{auto}{automatically detect between the binary and HTTP.} 24 | }} 25 | 26 | \item{username}{A \code{character} string that identifies the 27 | user ID to authenticate as.} 28 | 29 | \item{password}{A \code{character} string that specifies your 30 | password.} 31 | 32 | \item{session}{A \code{character} string that identifies the 33 | 32 character UUID of an existing session, if you want to 34 | connect to an existing session. This is rare.} 35 | 36 | \item{locale}{A \code{character} string that specifies the 37 | locale to use for the CAS session. By default, the locale 38 | is set to the locale of the server.} 39 | 40 | \item{authinfo}{A \code{character} string that specifies 41 | an alternative path to a .authinfo file that is used 42 | for authentication. By default, ~/.authinfo is used on 43 | Linux and \%HOMEDRIVE\% \\\%HOMEPATH\%\\_authinfo is used on 44 | Windows.} 45 | 46 | \item{path}{Base path of the connection URL} 47 | 48 | \item{authcode}{Authorization code from SASLogon used to retrieve 49 | an OAuth token.} 50 | } 51 | \value{ 52 | A CAS object. 53 | } 54 | \description{ 55 | An instance of this class represents a connection and session 56 | between the client (R) and the server (SAS Cloud Analytic Services). 57 | } 58 | 59 | \examples{ 60 | \dontrun{ 61 | # Use binary communication and credentals from the default authinfo location. 62 | s <- CAS('cloud.example.com', 5570) 63 | 64 | # Use HTTPS and credentials from the default authinfo location. 65 | s <- CAS('cloud.example.com', 8777, protocol='https') 66 | 67 | # Use binary or HTTP communication and credentials from an alternative authinfo. 68 | s <- CAS('cloud.example.com', 5570, protocol='auto', authinfo=~/alt.txt) 69 | 70 | # Use binary or HTTP communcation and specify credentials. 71 | s <- CAS('cloud.example.com', 8777, protocol='auto', username="sasdemo" 72 | password="!s3cret") 73 | } 74 | } 75 | % Copyright SAS Institute 76 | -------------------------------------------------------------------------------- /man/CASTable-Extract.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R, R/Ops.R 3 | \docType{methods} 4 | \name{[,CASTable-method} 5 | \alias{[,CASTable-method} 6 | \alias{[<-,CASTable-method} 7 | \alias{[[,CASTable-method} 8 | \alias{$,CASTable-method} 9 | \alias{$<-,CASTable-method} 10 | \alias{.cas.arith} 11 | \alias{-,CASTable,CASTable-method} 12 | \alias{-,CASTable,ANY-method} 13 | \alias{-,ANY,CASTable-method} 14 | \alias{+,CASTable,CASTable-method} 15 | \alias{+,CASTable,ANY-method} 16 | \alias{+,ANY,CASTable-method} 17 | \alias{/,CASTable,CASTable-method} 18 | \alias{/,CASTable,ANY-method} 19 | \alias{/,ANY,CASTable-method} 20 | \alias{*,CASTable,CASTable-method} 21 | \alias{*,CASTable,ANY-method} 22 | \alias{*,ANY,CASTable-method} 23 | \alias{^,CASTable,CASTable-method} 24 | \alias{^,CASTable,ANY-method} 25 | \alias{^,ANY,CASTable-method} 26 | \alias{\%\%,CASTable,CASTable-method} 27 | \alias{\%\%,CASTable,ANY-method} 28 | \alias{\%\%,ANY,CASTable-method} 29 | \alias{\%/\%,CASTable,CASTable-method} 30 | \alias{\%/\%,CASTable,ANY-method} 31 | \alias{\%/\%,ANY,CASTable-method} 32 | \alias{.cas.compare} 33 | \alias{>,CASTable,CASTable-method} 34 | \alias{>,CASTable,ANY-method} 35 | \alias{>,ANY,CASTable-method} 36 | \alias{<,CASTable,CASTable-method} 37 | \alias{<,CASTable,ANY-method} 38 | \alias{<,ANY,CASTable-method} 39 | \alias{>=,CASTable,CASTable-method} 40 | \alias{>=,CASTable,ANY-method} 41 | \alias{>=,ANY,CASTable-method} 42 | \alias{<=,CASTable,CASTable-method} 43 | \alias{<=,CASTable,ANY-method} 44 | \alias{<=,ANY,CASTable-method} 45 | \alias{==,CASTable,CASTable-method} 46 | \alias{==,CASTable,ANY-method} 47 | \alias{==,ANY,CASTable-method} 48 | \alias{!=,CASTable,CASTable-method} 49 | \alias{!=,CASTable,ANY-method} 50 | \alias{!=,ANY,CASTable-method} 51 | \alias{.cas.logic} 52 | \alias{&,CASTable,CASTable-method} 53 | \alias{&,CASTable,ANY-method} 54 | \alias{&,ANY,CASTable-method} 55 | \alias{|,CASTable,CASTable-method} 56 | \alias{|,CASTable,ANY-method} 57 | \alias{|,ANY,CASTable-method} 58 | \alias{!,CASTable-method} 59 | \title{Extract Columns from a CAS Table} 60 | \usage{ 61 | \S4method{[}{CASTable}(x, i, j, ..., drop = TRUE) 62 | 63 | \S4method{[}{CASTable}(x, i, j, ...) <- value 64 | 65 | \S4method{[[}{CASTable}(x, i) 66 | 67 | \S4method{$}{CASTable}(x, name) 68 | 69 | \S4method{$}{CASTable}(x, name) <- value 70 | 71 | .cas.arith(e1, op, e2) 72 | 73 | \S4method{-}{CASTable,CASTable}(e1, e2) 74 | 75 | \S4method{-}{CASTable,ANY}(e1, e2) 76 | 77 | \S4method{-}{ANY,CASTable}(e1, e2) 78 | 79 | \S4method{+}{CASTable,CASTable}(e1, e2) 80 | 81 | \S4method{+}{CASTable,ANY}(e1, e2) 82 | 83 | \S4method{+}{ANY,CASTable}(e1, e2) 84 | 85 | \S4method{/}{CASTable,CASTable}(e1, e2) 86 | 87 | \S4method{/}{CASTable,ANY}(e1, e2) 88 | 89 | \S4method{/}{ANY,CASTable}(e1, e2) 90 | 91 | \S4method{*}{CASTable,CASTable}(e1, e2) 92 | 93 | \S4method{*}{CASTable,ANY}(e1, e2) 94 | 95 | \S4method{*}{ANY,CASTable}(e1, e2) 96 | 97 | \S4method{^}{CASTable,CASTable}(e1, e2) 98 | 99 | \S4method{^}{CASTable,ANY}(e1, e2) 100 | 101 | \S4method{^}{ANY,CASTable}(e1, e2) 102 | 103 | \S4method{\%\%}{CASTable,CASTable}(e1, e2) 104 | 105 | \S4method{\%\%}{CASTable,ANY}(e1, e2) 106 | 107 | \S4method{\%\%}{ANY,CASTable}(e1, e2) 108 | 109 | \S4method{\%/\%}{CASTable,CASTable}(e1, e2) 110 | 111 | \S4method{\%/\%}{CASTable,ANY}(e1, e2) 112 | 113 | \S4method{\%/\%}{ANY,CASTable}(e1, e2) 114 | 115 | .cas.compare(e1, op, e2) 116 | 117 | \S4method{>}{CASTable,CASTable}(e1, e2) 118 | 119 | \S4method{>}{CASTable,ANY}(e1, e2) 120 | 121 | \S4method{>}{ANY,CASTable}(e1, e2) 122 | 123 | \S4method{<}{CASTable,CASTable}(e1, e2) 124 | 125 | \S4method{<}{CASTable,ANY}(e1, e2) 126 | 127 | \S4method{<}{ANY,CASTable}(e1, e2) 128 | 129 | \S4method{>=}{CASTable,CASTable}(e1, e2) 130 | 131 | \S4method{>=}{CASTable,ANY}(e1, e2) 132 | 133 | \S4method{>=}{ANY,CASTable}(e1, e2) 134 | 135 | \S4method{<=}{CASTable,CASTable}(e1, e2) 136 | 137 | \S4method{<=}{CASTable,ANY}(e1, e2) 138 | 139 | \S4method{<=}{ANY,CASTable}(e1, e2) 140 | 141 | \S4method{==}{CASTable,CASTable}(e1, e2) 142 | 143 | \S4method{==}{CASTable,ANY}(e1, e2) 144 | 145 | \S4method{==}{ANY,CASTable}(e1, e2) 146 | 147 | \S4method{!=}{CASTable,CASTable}(e1, e2) 148 | 149 | \S4method{!=}{CASTable,ANY}(e1, e2) 150 | 151 | \S4method{!=}{ANY,CASTable}(e1, e2) 152 | 153 | .cas.logic(e1, op, e2) 154 | 155 | \S4method{&}{CASTable,CASTable}(e1, e2) 156 | 157 | \S4method{&}{CASTable,ANY}(e1, e2) 158 | 159 | \S4method{&}{ANY,CASTable}(e1, e2) 160 | 161 | \S4method{|}{CASTable,CASTable}(e1, e2) 162 | 163 | \S4method{|}{CASTable,ANY}(e1, e2) 164 | 165 | \S4method{|}{ANY,CASTable}(e1, e2) 166 | 167 | \S4method{!}{CASTable}(x) 168 | } 169 | \description{ 170 | Extract Columns from a CAS Table 171 | } 172 | % Copyright SAS Institute 173 | -------------------------------------------------------------------------------- /man/CASTable-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \docType{class} 4 | \name{CASTable-class} 5 | \alias{CASTable-class} 6 | \alias{CASTable} 7 | \title{CAS Table Object} 8 | \value{ 9 | \code{CASTable} 10 | } 11 | \description{ 12 | CAS Table Object 13 | } 14 | \section{Slots}{ 15 | 16 | \describe{ 17 | \item{\code{conn}}{A \code{\link{CAS}} object that represents the connection and 18 | session on the server.} 19 | 20 | \item{\code{tname}}{An optional \code{character} string for the table name.} 21 | 22 | \item{\code{caslib}}{An optional \code{character} string that identifies the caslib for the 23 | in-memory table. Specify this parameter to override the active caslib.} 24 | 25 | \item{\code{where}}{An optional \code{character} string that specifies a filter for the 26 | rows to process. The filter uses syntax that is specific to SAS.} 27 | 28 | \item{\code{orderby}}{An optional \code{list} of column names. Rows are partitioned according 29 | to the columns in the groupby parameter and then ordered according to 30 | the values of the columns specified in this parameter.} 31 | 32 | \item{\code{groupby}}{An optional \code{list} of column names. If you specify this parameter 33 | when you load an in-memory table, then the table is partitioned by the 34 | columns. If you specify this parameter when running an action, then 35 | BY-groups are formed temporarily for the duration of the action.} 36 | 37 | \item{\code{gbmode}}{An optional \code{character} string. Values are NOSORT (default) or 38 | REDISTRIBUTE. See the CAS product documentation for more information.} 39 | 40 | \item{\code{computedOnDemand}}{An optional \code{logical} flag that indicates whether to 41 | the computed variables are created when the table is loaded (False) or to compute 42 | them when an action begins (True).} 43 | 44 | \item{\code{computedVars}}{An optional \code{character} string list that identifies the 45 | name and optional information such as a format and label.} 46 | 47 | \item{\code{computedVarsProgram}}{An optional \code{character} string list. Specify the 48 | expression to use for computing each of the computed variables.} 49 | 50 | \item{\code{names}}{An optional \code{list} of column names.} 51 | }} 52 | 53 | \seealso{ 54 | \code{as.casTable}, \code{defCasTable} 55 | } 56 | % Copyright SAS Institute 57 | -------------------------------------------------------------------------------- /man/as.casDataFrame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CASdf.R 3 | \name{as.casDataFrame} 4 | \alias{as.casDataFrame} 5 | \title{Convert an \R Data Frame to a CAS Data Frame} 6 | \usage{ 7 | as.casDataFrame( 8 | df, 9 | name = "", 10 | label = "", 11 | title = "", 12 | attrs = list(), 13 | col.labels = "", 14 | col.formats = "", 15 | col.attrs = list(), 16 | col.sizes = list(), 17 | col.types = "", 18 | col.widths = 0 19 | ) 20 | } 21 | \value{ 22 | casDataFrame 23 | } 24 | \description{ 25 | This function is rarely used for programming. It is 26 | used by the package to associate CAS metadata with 27 | tabular data that is returned by CAS actions. 28 | } 29 | \examples{ 30 | \dontrun{ 31 | cdf2 = as.casDataFrame(df3[1:4]) 32 | cdf = as.casDataFrame(iris) 33 | } 34 | } 35 | % Copyright SAS Institute 36 | -------------------------------------------------------------------------------- /man/as.casTable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \name{as.casTable} 4 | \alias{as.casTable} 5 | \title{Upload an Object to a CAS Table} 6 | \usage{ 7 | as.casTable(conn, df, casOut = "") 8 | } 9 | \arguments{ 10 | \item{conn}{A \code{\link{CAS}} object that represents 11 | a connection and session in CAS.} 12 | 13 | \item{df}{A \code{data.frame} object with the data to 14 | upload to CAS.} 15 | 16 | \item{casOut}{An optional \code{character} or list. If 17 | you specify a string, then the string is used as the 18 | in-memory table name. A list can be used to specify 19 | properties for the in-memory table as follows: 20 | \describe{ 21 | \item{\code{name}}{An optional \code{character} that 22 | specifies the name for the in-memory table. By 23 | default, the name of the data frame is used.} 24 | \item{\code{caslib}}{An optional \code{character} that 25 | specifies the caslib. Specify this parameter to 26 | override the active caslib.} 27 | \item{\code{label}}{An optional \code{character} that 28 | specifies a descriptive label for the data.} 29 | \item{\code{replace}}{An optional \code{logical}. When 30 | set to TRUE, you can replace an existing in-memory 31 | table with the same name in the same caslib. The 32 | default value is FALSE.} 33 | \item{\code{promote}}{An optional \code{logical}. When 34 | set to TRUE, the in-memory table has global scope and 35 | can be available to other CAS sessions (subject to 36 | access controls). The default value is FALSE and 37 | the in-memory table has session scope so that it is 38 | accessible with the session that uploaded the table 39 | only. Session-scope tables are ideal for data analysis. 40 | Global-scope tables are better suited for reporting.} 41 | \item{\code{replication}}{An optional \code{numeric} that 42 | specifies the number of redundant copies of in-memory 43 | blocks. This parameter applies to distributed servers 44 | only. The default value is 1.} 45 | }} 46 | } 47 | \value{ 48 | \code{\link{CASTable}} 49 | } 50 | \description{ 51 | Uploads an \R data frame to CAS and returns a 52 | \code{\link{CASTable}} object. The CASTable object 53 | is a reference in \R (the client) to the in-memory 54 | table that is in CAS (the server). 55 | } 56 | \examples{ 57 | \dontrun{ 58 | s <- CAS('cloud.example.com', 5570) 59 | irisct <- as.casTable(s, iris) 60 | 61 | # Specify a name for the in-memory table. 62 | mtcarsct <- as.casTable(s, mtcars, casOut="mtcarsct") 63 | 64 | # Avoid replacing an existing in-memory table. 65 | mtcarsct <- as.casTable(s, mtcars, casOut=list(name="mtcarsct", replace=FALSE)) 66 | } 67 | } 68 | % Copyright SAS Institute 69 | -------------------------------------------------------------------------------- /man/cas.close.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/swat.R 3 | \name{cas.close} 4 | \alias{cas.close} 5 | \title{Close a CAS connection while leaving the session alive} 6 | \usage{ 7 | cas.close(conn) 8 | } 9 | \arguments{ 10 | \item{CAS}{The CAS connection object} 11 | } 12 | \description{ 13 | Close a CAS connection while leaving the session alive 14 | } 15 | -------------------------------------------------------------------------------- /man/cas.count.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.count} 4 | \alias{cas.count} 5 | \title{Count of Nonmissing Values} 6 | \usage{ 7 | cas.count(CASTable) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | casDataFrame 14 | 15 | The result includes one row for each numeric variable 16 | and a column that is named N for the nonmissing count. 17 | } 18 | \description{ 19 | Returns the number of nonmissing values in the input 20 | table by column. 21 | } 22 | \details{ 23 | This function operates on numeric columns only. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | cas.count(ct[1:4]) 28 | cas.count(ct$n2) 29 | } 30 | } 31 | \seealso{ 32 | \code{cas.nmiss} to count missing values. 33 | } 34 | % Copyright SAS Institute 35 | -------------------------------------------------------------------------------- /man/cas.css.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.css} 4 | \alias{cas.css} 5 | \title{Corrected Sum of Squares} 6 | \usage{ 7 | cas.css(CASTable) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | vector 14 | 15 | The result is a named numeric vector. You can access 16 | the corrected sum of squares by column name or index. 17 | } 18 | \description{ 19 | Returns the corrected sum of squares of the 20 | values for each column in the input table. 21 | } 22 | \details{ 23 | This function operates on numeric columns only. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | x <- cas.css(irisct) 28 | x['Sepal.Length'] 29 | x[1:2] 30 | } 31 | } 32 | % Copyright SAS Institute 33 | -------------------------------------------------------------------------------- /man/cas.cv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.cv} 4 | \alias{cas.cv} 5 | \title{Coefficient of Variation} 6 | \usage{ 7 | cas.cv(CASTable) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | vector 14 | 15 | The result is a named numeric vector. You can access 16 | the coefficient of variation by column name or index. 17 | } 18 | \description{ 19 | Returns the coefficient of variation of the 20 | values for each column in the input table. 21 | } 22 | \details{ 23 | This function operates on numeric columns only. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | x <- cas.cv(irisct) 28 | x['Sepal.Length'] 29 | x[1:2] 30 | } 31 | } 32 | % Copyright SAS Institute 33 | -------------------------------------------------------------------------------- /man/cas.max.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.max} 4 | \alias{cas.max} 5 | \title{Maximum Values} 6 | \usage{ 7 | cas.max(CASTable) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | casDataFrame 14 | 15 | The result includes one row for each numeric variable 16 | and a column that is named Max for the maximum value. 17 | } 18 | \description{ 19 | Returns the maximum value for each column in 20 | the input table. 21 | } 22 | \details{ 23 | This function operates on numeric columns only. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | cas.max(ct[1:4]) 28 | cas.max(ct$n2) 29 | } 30 | } 31 | \seealso{ 32 | \code{max,CASTable-method} 33 | } 34 | % Copyright SAS Institute 35 | -------------------------------------------------------------------------------- /man/cas.mean.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.mean} 4 | \alias{cas.mean} 5 | \title{Average Values} 6 | \usage{ 7 | cas.mean(CASTable) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | casDataFrame 14 | 15 | The result includes one row for each numeric variable 16 | and a column that is named Mean for the mean value. 17 | } 18 | \description{ 19 | Returns the mean value for each column in 20 | the input table. 21 | } 22 | \details{ 23 | This function operates on numeric columns only. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | cas.mean(ct[1:4]) 28 | cas.mean(ct$n2) 29 | } 30 | } 31 | \seealso{ 32 | \code{mean,CASTable-method} 33 | } 34 | % Copyright SAS Institute 35 | -------------------------------------------------------------------------------- /man/cas.median.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.median} 4 | \alias{cas.median} 5 | \title{Median Values} 6 | \usage{ 7 | cas.median(CASTable, q) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | data.frame 14 | 15 | The result includes one row for each numeric variable 16 | and a column that is named Median for the median value. 17 | } 18 | \description{ 19 | Returns the median value for each column in 20 | the input table. 21 | } 22 | \details{ 23 | This function operates on numeric columns only. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | cas.median(ct[1:4]) 28 | cas.median(ct$n2) 29 | } 30 | } 31 | \seealso{ 32 | \code{median,CASTable-method} 33 | } 34 | % Copyright SAS Institute 35 | -------------------------------------------------------------------------------- /man/cas.min.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.min} 4 | \alias{cas.min} 5 | \title{Minimum Values} 6 | \usage{ 7 | cas.min(CASTable) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | casDataFrame 14 | 15 | The result includes one row for each numeric variable 16 | and a column that is named Minimum for the minimum value. 17 | } 18 | \description{ 19 | Returns the minimum value for each column in 20 | the input table. 21 | } 22 | \details{ 23 | This function operates on numeric columns only. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | cas.min(ct[1:4]) 28 | cas.min(ct$n2) 29 | } 30 | } 31 | \seealso{ 32 | \code{min,CASTable-method} 33 | } 34 | % Copyright SAS Institute 35 | -------------------------------------------------------------------------------- /man/cas.mode.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.mode} 4 | \alias{cas.mode} 5 | \title{Mode Value} 6 | \usage{ 7 | cas.mode(CASTable) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | data.frame 14 | 15 | The result includes one row for each variable. 16 | One column is named Mode for the most common value. 17 | Another column is named Count to show the number of rows 18 | with the most common value. 19 | } 20 | \description{ 21 | Returns the value that occurs most often for each column in 22 | the input table and the count for the value. 23 | } 24 | \details{ 25 | This function operates on numeric and character columns. 26 | } 27 | \examples{ 28 | \dontrun{ 29 | cas.mode(ct[1:4]) 30 | cas.mode(ct$n2) 31 | } 32 | } 33 | % Copyright SAS Institute 34 | -------------------------------------------------------------------------------- /man/cas.nmiss.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.nmiss} 4 | \alias{cas.nmiss} 5 | \title{Number of Missing Values} 6 | \usage{ 7 | cas.nmiss(CASTable) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | vector 14 | 15 | The result is a named numeric vector. You can access 16 | the count of missing values by column name or index. 17 | } 18 | \description{ 19 | Returns the number of missing values in the input 20 | table by column. 21 | } 22 | \details{ 23 | This function operates on numeric columns only. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | x <- cas.nmiss(irisct) 28 | x['Sepal.Length'] 29 | x[1:2] 30 | } 31 | } 32 | \seealso{ 33 | \code{cas.count} to count nonmissing values. 34 | } 35 | % Copyright SAS Institute 36 | -------------------------------------------------------------------------------- /man/cas.probt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.probt} 4 | \alias{cas.probt} 5 | \title{P-Value of the T-Statistics} 6 | \usage{ 7 | cas.probt(CASTable) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | vector 14 | 15 | The result is a named numeric vector. You can access 16 | the p-value by column name or index. 17 | } 18 | \description{ 19 | Returns the p-values for the 20 | values for each column in the input table. 21 | } 22 | \details{ 23 | This function operates on numeric columns only. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | x <- cas.probt(irisct) 28 | x['Sepal.Length'] 29 | x[1:2] 30 | } 31 | } 32 | % Copyright SAS Institute 33 | -------------------------------------------------------------------------------- /man/cas.quantile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.quantile} 4 | \alias{cas.quantile} 5 | \title{Quantile and Percentile Values} 6 | \usage{ 7 | cas.quantile(CASTable, q) 8 | } 9 | \arguments{ 10 | \item{q}{A list of numeric values.} 11 | 12 | \item{x}{CASTable.} 13 | } 14 | \value{ 15 | data.frame 16 | 17 | The result includes one row for the variable, the requested 18 | percentile, and the value. 19 | } 20 | \description{ 21 | Returns the requested percentiles for each column in 22 | the input table. 23 | } 24 | \details{ 25 | This function operates on numeric columns only. 26 | } 27 | \examples{ 28 | \dontrun{ 29 | cas.quantile(ct[1:4], q=50) 30 | cas.quantile(ct$n2, q=c(10, 25, 50, 75, 90)) 31 | } 32 | } 33 | % Copyright SAS Institute 34 | -------------------------------------------------------------------------------- /man/cas.read.csv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_write.R 3 | \name{cas.read.csv} 4 | \alias{cas.read.csv} 5 | \title{Read a CSV File and Upload to a CAS Table} 6 | \usage{ 7 | cas.read.csv( 8 | conn, 9 | file, 10 | header = TRUE, 11 | sep = ",", 12 | quote = "\\"", 13 | dec = ".", 14 | fill = TRUE, 15 | comment.char = "", 16 | casOut = list(name = "", replace = FALSE), 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{conn}{An instance of a CAS object that represents 22 | a connection and CAS session.} 23 | 24 | \item{file}{An \code{character} string that specifies 25 | the filename or connection for the data to read.} 26 | 27 | \item{header}{An optional \code{logical} that specifies 28 | whether the first line of the file contains variable 29 | names.} 30 | 31 | \item{sep}{A \code{character} that specifies the field 32 | delimiter. This value is passed to \code{read.csv}.} 33 | 34 | \item{quote}{A \code{character} string that specifies 35 | the characters that enclose character data type 36 | variables. This value is passed to \code{read.csv}.} 37 | 38 | \item{dec}{An optional \code{character} to represent the decimal 39 | separator. This value is passed to \code{read.csv}.} 40 | 41 | \item{fill}{An optional \code{logical} value. When set to 42 | TRUE, blank fields are implicitly added for rows that have 43 | unequal length. This value is passed to \code{read.csv}.} 44 | 45 | \item{comment.char}{An optional \code{character} that 46 | specifies the character to interpret as the beginning of a 47 | comment. This value is passed to \code{read.csv}.} 48 | 49 | \item{casOut}{An optional \code{character} or list. If 50 | you specify a string, then the string is used as the 51 | in-memory table name. A list can be used to specify 52 | properties for the in-memory table as follows: 53 | \describe{ 54 | \item{\code{name}}{An optional \code{character} that 55 | specifies the name for the in-memory table. By 56 | default, the name of the data frame is used.} 57 | \item{\code{caslib}}{An optional \code{character} that 58 | specifies the caslib. Specify this parameter to 59 | override the active caslib.} 60 | \item{\code{label}}{An optional \code{character} that 61 | specifies a descriptive label for the data.} 62 | \item{\code{replace}}{An optional \code{logical}. When 63 | set to TRUE, you can replace an existing in-memory 64 | table with the same name in the same caslib. The 65 | default value is FALSE.} 66 | \item{\code{promote}}{An optional \code{logical}. When 67 | set to TRUE, the in-memory table has global scope and 68 | can be available to other CAS sessions (subject to 69 | access controls). The default value is FALSE and 70 | the in-memory table has session scope so that it is 71 | accessible with the session that uploaded the table 72 | only. Session-scope tables are ideal for data analysis. 73 | Global-scope tables are better suited for reporting.} 74 | \item{\code{replication}}{An optional \code{numeric} that 75 | specifies the number of redundant copies of in-memory 76 | blocks. This parameter applies to distributed servers 77 | only. The default value is 1.} 78 | }} 79 | 80 | \item{\dots}{Optional parameters that are passed to 81 | \code{read.csv}.} 82 | } 83 | \value{ 84 | \code{\link{CASTable}} 85 | } 86 | \description{ 87 | This function is a convenience wrapper for 88 | the \R \code{read.csv} and \code{as.casTable} functions. 89 | After reading the file that is accessible to the \R 90 | client, it is uploaded to an in-memory table in 91 | CAS (the server). 92 | } 93 | \examples{ 94 | \dontrun{ 95 | # Upload a CSV, the in-memory table is named HEART 96 | heartct <- cas.read.csv(s, "http://support.sas.com/documentation/ 97 | onlinedoc/viya/exampledatasets/heart.csv") 98 | 99 | # Upload the same CSV, name the in-memory table HEARTCT 100 | heartct <- cas.read.csv(s, "http://support.sas.com/documentation/ 101 | onlinedoc/viya/exampledatasets/heart.csv", 102 | casOut=list(name="heartct", replace=TRUE)) 103 | } 104 | } 105 | \seealso{ 106 | Other functions for loading in-memory data: 107 | \code{\link{cas.read.jmp}()}, 108 | \code{\link{cas.read.sas7bdat}()}, 109 | \code{\link{cas.read.table}()}, 110 | \code{\link{cas.read.xlsx}()}, 111 | \code{\link{cas.readRDS}()} 112 | } 113 | \concept{functions for loading in-memory data} 114 | % Copyright SAS Institute 115 | -------------------------------------------------------------------------------- /man/cas.read.jmp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_write.R 3 | \name{cas.read.jmp} 4 | \alias{cas.read.jmp} 5 | \title{Upload a JMP File to a CAS Table} 6 | \usage{ 7 | cas.read.jmp(conn, file, casOut = NULL) 8 | } 9 | \arguments{ 10 | \item{conn}{An instance of a CAS object that represents 11 | a connection and CAS session.} 12 | 13 | \item{file}{An \code{character} string that specifies 14 | the JMP file.} 15 | 16 | \item{casOut}{An optional \code{character} or list. If 17 | you specify a string, then the string is used as the 18 | in-memory table name. A list can be used to specify 19 | properties for the in-memory table as follows: 20 | \describe{ 21 | \item{\code{name}}{An optional \code{character} that 22 | specifies the name for the in-memory table. By 23 | default, the name of the data frame is used.} 24 | \item{\code{caslib}}{An optional \code{character} that 25 | specifies the caslib. Specify this parameter to 26 | override the active caslib.} 27 | \item{\code{label}}{An optional \code{character} that 28 | specifies a descriptive label for the data.} 29 | \item{\code{replace}}{An optional \code{logical}. When 30 | set to TRUE, you can replace an existing in-memory 31 | table with the same name in the same caslib. The 32 | default value is FALSE.} 33 | \item{\code{promote}}{An optional \code{logical}. When 34 | set to TRUE, the in-memory table has global scope and 35 | can be available to other CAS sessions (subject to 36 | access controls). The default value is FALSE and 37 | the in-memory table has session scope so that it is 38 | accessible with the session that uploaded the table 39 | only. Session-scope tables are ideal for data analysis. 40 | Global-scope tables are better suited for reporting.} 41 | \item{\code{replication}}{An optional \code{numeric} that 42 | specifies the number of redundant copies of in-memory 43 | blocks. This parameter applies to distributed servers 44 | only. The default value is 1.} 45 | }} 46 | } 47 | \value{ 48 | \code{\link{CASTable}} 49 | } 50 | \description{ 51 | This function transfers a JMP file (.jmp) from \R 52 | (the client) to the CAS server. The 53 | server imports the data and \R returns a CASTable 54 | object to reference the in-memory table in CAS. 55 | } 56 | \examples{ 57 | \dontrun{ 58 | spring_example <- cas.read.jmp(s, "/path/to/Spring\ Example.jmp", 59 | casOut=list(name="spring_example")) 60 | } 61 | } 62 | \seealso{ 63 | Other functions for loading in-memory data: 64 | \code{\link{cas.read.csv}()}, 65 | \code{\link{cas.read.sas7bdat}()}, 66 | \code{\link{cas.read.table}()}, 67 | \code{\link{cas.read.xlsx}()}, 68 | \code{\link{cas.readRDS}()} 69 | } 70 | \concept{functions for loading in-memory data} 71 | % Copyright SAS Institute 72 | -------------------------------------------------------------------------------- /man/cas.read.sas7bdat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_write.R 3 | \name{cas.read.sas7bdat} 4 | \alias{cas.read.sas7bdat} 5 | \title{Upload a SAS Data Set to a CAS Table} 6 | \usage{ 7 | cas.read.sas7bdat(conn, file, casOut = list(name = "", replace = FALSE)) 8 | } 9 | \arguments{ 10 | \item{conn}{An instance of a CAS object that represents 11 | a connection and CAS session.} 12 | 13 | \item{file}{An \code{character} string that specifies 14 | the SAS data set (.sas7bdat file).} 15 | 16 | \item{casOut}{An optional \code{character} or list. If 17 | you specify a string, then the string is used as the 18 | in-memory table name. A list can be used to specify 19 | properties for the in-memory table as follows: 20 | \describe{ 21 | \item{\code{name}}{An optional \code{character} that 22 | specifies the name for the in-memory table. By 23 | default, the name of the data frame is used.} 24 | \item{\code{caslib}}{An optional \code{character} that 25 | specifies the caslib. Specify this parameter to 26 | override the active caslib.} 27 | \item{\code{label}}{An optional \code{character} that 28 | specifies a descriptive label for the data.} 29 | \item{\code{replace}}{An optional \code{logical}. When 30 | set to TRUE, you can replace an existing in-memory 31 | table with the same name in the same caslib. The 32 | default value is FALSE.} 33 | \item{\code{promote}}{An optional \code{logical}. When 34 | set to TRUE, the in-memory table has global scope and 35 | can be available to other CAS sessions (subject to 36 | access controls). The default value is FALSE and 37 | the in-memory table has session scope so that it is 38 | accessible with the session that uploaded the table 39 | only. Session-scope tables are ideal for data analysis. 40 | Global-scope tables are better suited for reporting.} 41 | \item{\code{replication}}{An optional \code{numeric} that 42 | specifies the number of redundant copies of in-memory 43 | blocks. This parameter applies to distributed servers 44 | only. The default value is 1.} 45 | }} 46 | } 47 | \value{ 48 | \code{\link{CASTable}} 49 | } 50 | \description{ 51 | This function transfers a SAS data set (.sas7bdat) 52 | file from \R (the client) to the CAS server. The 53 | server imports the data and \R returns a CASTable 54 | object to reference the in-memory table in CAS. 55 | } 56 | \examples{ 57 | \dontrun{ 58 | gold_medals <- cas.read.sas7bdat(s, "/path/to/gold_medals.sas7bdat") 59 | } 60 | } 61 | \seealso{ 62 | Other functions for loading in-memory data: 63 | \code{\link{cas.read.csv}()}, 64 | \code{\link{cas.read.jmp}()}, 65 | \code{\link{cas.read.table}()}, 66 | \code{\link{cas.read.xlsx}()}, 67 | \code{\link{cas.readRDS}()} 68 | } 69 | \concept{functions for loading in-memory data} 70 | % Copyright SAS Institute 71 | -------------------------------------------------------------------------------- /man/cas.read.table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_write.R 3 | \name{cas.read.table} 4 | \alias{cas.read.table} 5 | \title{Read a File and Upload to a CAS Table} 6 | \usage{ 7 | cas.read.table( 8 | conn, 9 | file, 10 | header = FALSE, 11 | sep = "", 12 | quote = "\\"'", 13 | dec = ".", 14 | numerals = c("allow.loss", "warn.loss", "no.loss"), 15 | row.names, 16 | col.names, 17 | as.is = !stringsAsFactors, 18 | na.strings = "NA", 19 | colClasses = NA, 20 | nrows = -1, 21 | skip = 0, 22 | check.names = TRUE, 23 | fill = !blank.lines.skip, 24 | strip.white = FALSE, 25 | blank.lines.skip = TRUE, 26 | comment.char = "#", 27 | allowEscapes = FALSE, 28 | flush = FALSE, 29 | stringsAsFactors = default.stringsAsFactors(), 30 | fileEncoding = "", 31 | encoding = "unknown", 32 | text, 33 | skipNul = FALSE, 34 | casOut = list(name = "", replace = FALSE) 35 | ) 36 | } 37 | \arguments{ 38 | \item{conn}{An instance of a CAS object that represents 39 | a connection and CAS session.} 40 | 41 | \item{file}{An \code{character} string that 42 | specifies the filename. This value is passed to \code{read.table}.} 43 | 44 | \item{header}{An optional \code{logical} that specifies 45 | whether the first line of the file contains variable 46 | names.} 47 | 48 | \item{sep}{An optional \code{character} that is used to specify 49 | the field delimiter for the file. This value is passed to 50 | \code{write.table}.} 51 | 52 | \item{quote}{An optional \code{character} string that specifies 53 | the characters that enclose character data. The value is 54 | passed to \code{read.table}.} 55 | 56 | \item{dec}{An optional \code{character} that specifies the decimal 57 | separator. This value is passed to \code{read.table}.} 58 | 59 | \item{numerals}{An optional \code{character} string that specifies 60 | how to interpret numbers that can lose precision due to the 61 | conversion from text to double precision. This value is passed 62 | to \code{read.table}.} 63 | 64 | \item{row.names}{An optional \code{character} vector of row 65 | names. This value is passed to \code{read.table}.} 66 | 67 | \item{col.names}{An optional \code{character} vector of names 68 | for the variables. The default is to use "V" followed by the 69 | column number. This value is passed to \code{read.table}.} 70 | 71 | \item{as.is}{An optional vector of \code{logical}, \code{numeric}, 72 | or \code{character} indices that specify the columns that are not 73 | converted to factors. This value is passed to \code{read.table}.} 74 | 75 | \item{na.strings}{An optional \code{character} vector that specifies 76 | the characters to interpret as NA. This value is passed to 77 | \code{read.table}.} 78 | 79 | \item{colClasses}{An optional \code{character} vector that 80 | specifies the classes for the columns. This value is passed 81 | to \code{read.table}.} 82 | 83 | \item{nrows}{An optional \code{numeric} that specifies the maximum 84 | number of rows to read. This value is passed to \code{read.table}.} 85 | 86 | \item{skip}{An optional \code{numeric} that specifies the number of 87 | lines to skip in the file before reading data. This value is 88 | passed to \code{read.table}.} 89 | 90 | \item{check.names}{An optional \code{logical} that specifies 91 | whether variable names from the file are valid names. This value 92 | is passed to \code{read.table}.} 93 | 94 | \item{fill}{An optional \code{logical} value. When set to 95 | TRUE, blank fields are implicitly added for rows that have 96 | unequal length. This value is passed to \code{read.table}.} 97 | 98 | \item{strip.white}{An optional \code{logical} that specifies 99 | whether white space characters are stripped from character data 100 | that are not enclosed with quotation marks. This value is 101 | ignored unless sep is specified. This value is passed to 102 | \code{read.table}.} 103 | 104 | \item{blank.lines.skip}{An optional \code{logical} that specifies 105 | whether blank lines in the file are ignored. This value is 106 | passed to \code{read.table}.} 107 | 108 | \item{comment.char}{An optional \code{character} that 109 | specifies the character to interpret as the beginning of a 110 | comment. This value is passed to \code{read.table}.} 111 | 112 | \item{allowEscapes}{An optional \code{logical} that specifies 113 | whether C-style escape characters such as \code{\\n} are 114 | interpreted or are read verbatim. This value is passed to 115 | \code{read.table}.} 116 | 117 | \item{flush}{An optional \code{logical} that specifies whether 118 | input that follows the last field to read is flushed. Setting 119 | this argument to TRUE enables adding comments to the end of 120 | data lines. This value is passed to \code{read.table}.} 121 | 122 | \item{stringsAsFactors}{An optional \code{logical} that specifies 123 | whether character vectors are converted to factors. This argument 124 | is overridden by as.is and colClasses. This value is passed to 125 | \code{read.table}.} 126 | 127 | \item{fileEncoding}{An optional \code{character} string that 128 | specifies the encoding to use for reading the file. This 129 | value is passed to \code{read.table}.} 130 | 131 | \item{encoding}{An optional \code{character} string that specifies 132 | the encoding for character data. This value is passed to 133 | \code{read.table}.} 134 | 135 | \item{text}{An optional \code{character} string. This value is 136 | passed to \code{read.table}.} 137 | 138 | \item{skipNul}{An optional \code{logical} that is passed to 139 | \code{read.table}.} 140 | 141 | \item{casOut}{An optional \code{character} or list. If 142 | you specify a string, then the string is used as the 143 | in-memory table name. A list can be used to specify 144 | properties for the in-memory table as follows: 145 | \describe{ 146 | \item{\code{name}}{An optional \code{character} that 147 | specifies the name for the in-memory table. By 148 | default, the name of the data frame is used.} 149 | \item{\code{caslib}}{An optional \code{character} that 150 | specifies the caslib. Specify this parameter to 151 | override the active caslib.} 152 | \item{\code{label}}{An optional \code{character} that 153 | specifies a descriptive label for the data.} 154 | \item{\code{replace}}{An optional \code{logical}. When 155 | set to TRUE, you can replace an existing in-memory 156 | table with the same name in the same caslib. The 157 | default value is FALSE.} 158 | \item{\code{promote}}{An optional \code{logical}. When 159 | set to TRUE, the in-memory table has global scope and 160 | can be available to other CAS sessions (subject to 161 | access controls). The default value is FALSE and 162 | the in-memory table has session scope so that it is 163 | accessible with the session that uploaded the table 164 | only. Session-scope tables are ideal for data analysis. 165 | Global-scope tables are better suited for reporting.} 166 | \item{\code{replication}}{An optional \code{numeric} that 167 | specifies the number of redundant copies of in-memory 168 | blocks. This parameter applies to distributed servers 169 | only. The default value is 1.} 170 | }} 171 | } 172 | \value{ 173 | \code{\link{CASTable}} 174 | } 175 | \description{ 176 | This function is a convenience wrapper for 177 | the \R \code{read.table} and \code{as.casTable} functions. 178 | After reading the file that is accessible to the \R 179 | client, it is uploaded to an in-memory table in 180 | CAS (the server). 181 | } 182 | \examples{ 183 | \dontrun{ 184 | myCasTable <- cas.read.table(s, "/path/to/data.tsv", header=TRUE, 185 | sep="\t", casOut=list(name="mycastable")) 186 | } 187 | } 188 | \seealso{ 189 | Other functions for loading in-memory data: 190 | \code{\link{cas.read.csv}()}, 191 | \code{\link{cas.read.jmp}()}, 192 | \code{\link{cas.read.sas7bdat}()}, 193 | \code{\link{cas.read.xlsx}()}, 194 | \code{\link{cas.readRDS}()} 195 | } 196 | \concept{functions for loading in-memory data} 197 | % Copyright SAS Institute 198 | -------------------------------------------------------------------------------- /man/cas.read.xlsx.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_write.R 3 | \name{cas.read.xlsx} 4 | \alias{cas.read.xlsx} 5 | \title{Read an XLSX File and Upload to a CAS Table} 6 | \usage{ 7 | cas.read.xlsx( 8 | conn, 9 | file, 10 | sheetIndex = 1, 11 | sheetName = NULL, 12 | rowIndex = NULL, 13 | startRow = NULL, 14 | endRow = NULL, 15 | colIndex = NULL, 16 | as.data.frame = TRUE, 17 | header = TRUE, 18 | colClasses = NA, 19 | keepFormulas = FALSE, 20 | encoding = "unknown", 21 | casOut = list(name = "", replace = FALSE) 22 | ) 23 | } 24 | \arguments{ 25 | \item{conn}{An instance of a CAS object that represents 26 | a connection and CAS session.} 27 | 28 | \item{file}{An \code{character} string that 29 | specifies the filename for the XLSX file. 30 | This value is passed to \code{read.xslx}.} 31 | 32 | \item{sheetIndex}{An optional \code{numeric} that specifies 33 | the sheet in the workbook. This value is passed to 34 | \code{read.xlsx}.} 35 | 36 | \item{sheetName}{An optional \code{character} string that 37 | specifies the sheet name in the workbook. This value is 38 | passed to \code{read.xlsx}.} 39 | 40 | \item{rowIndex}{An optional \code{numeric} vector that 41 | specifies the rows to read from the workbook. By default, 42 | all rows are read. This value is passed to \code{read.xlsx}.} 43 | 44 | \item{startRow}{An optional \code{numeric} that specifies 45 | the first row of the workbook to read. This value is 46 | ignored of rowIndex is specified. This value is passed to 47 | \code{read.xlsx}.} 48 | 49 | \item{endRow}{An optional \code{numeric} that specifies the 50 | last row of the workbook to read. This value is ignored if 51 | rowIndex is specified. This value is passed to \code{read.xlsx}.} 52 | 53 | \item{colIndex}{An optional \code{numeric} vector that specifies 54 | the variables to read from the workbook. By default, 55 | all variables are read. This value is passed to \code{read.xlsx}.} 56 | 57 | \item{as.data.frame}{An optional \code{logical} value that 58 | specifies whether the data should be coerced into a data frame. 59 | This value is passed to \code{read.xlsx}.} 60 | 61 | \item{header}{An optional \code{logical} that specifies 62 | whether the first line of the file contains variable 63 | names.} 64 | 65 | \item{colClasses}{An optional \code{character} vector that 66 | specifies the classes for the columns. This value is passed 67 | to \code{read.xlsx}.} 68 | 69 | \item{keepFormulas}{An optional \code{logical} value that specifies 70 | whether Excel formulas are included as text or if they are 71 | evaluated and the result is read as data. This value is passed 72 | to \code{read.xlsx}.} 73 | 74 | \item{encoding}{An optional \code{character} string that specifies 75 | the encoding for character data. This value is passed to 76 | \code{read.xlsx}.} 77 | 78 | \item{casOut}{An optional \code{character} or list. If 79 | you specify a string, then the string is used as the 80 | in-memory table name. A list can be used to specify 81 | properties for the in-memory table as follows: 82 | \describe{ 83 | \item{\code{name}}{An optional \code{character} that 84 | specifies the name for the in-memory table. By 85 | default, the name of the data frame is used.} 86 | \item{\code{caslib}}{An optional \code{character} that 87 | specifies the caslib. Specify this parameter to 88 | override the active caslib.} 89 | \item{\code{label}}{An optional \code{character} that 90 | specifies a descriptive label for the data.} 91 | \item{\code{replace}}{An optional \code{logical}. When 92 | set to TRUE, you can replace an existing in-memory 93 | table with the same name in the same caslib. The 94 | default value is FALSE.} 95 | \item{\code{promote}}{An optional \code{logical}. When 96 | set to TRUE, the in-memory table has global scope and 97 | can be available to other CAS sessions (subject to 98 | access controls). The default value is FALSE and 99 | the in-memory table has session scope so that it is 100 | accessible with the session that uploaded the table 101 | only. Session-scope tables are ideal for data analysis. 102 | Global-scope tables are better suited for reporting.} 103 | \item{\code{replication}}{An optional \code{numeric} that 104 | specifies the number of redundant copies of in-memory 105 | blocks. This parameter applies to distributed servers 106 | only. The default value is 1.} 107 | }} 108 | } 109 | \value{ 110 | \code{\link{CASTable}} 111 | } 112 | \description{ 113 | This function is a convenience wrapper for 114 | the \R \code{read.xlsx} and \code{as.casTable} functions. 115 | After reading the file that is accessible to the \R 116 | client, it is uploaded to an in-memory table in 117 | CAS (the server). 118 | } 119 | \examples{ 120 | \dontrun{ 121 | myCasTable <- cas.read.xlsx(s, file="/path/to/data_out.xlsx", 122 | sheetIndex = 1, 123 | casOut=list(name="mycastable", replace=TRUE)) 124 | } 125 | } 126 | \seealso{ 127 | Other functions for loading in-memory data: 128 | \code{\link{cas.read.csv}()}, 129 | \code{\link{cas.read.jmp}()}, 130 | \code{\link{cas.read.sas7bdat}()}, 131 | \code{\link{cas.read.table}()}, 132 | \code{\link{cas.readRDS}()} 133 | } 134 | \concept{functions for loading in-memory data} 135 | % Copyright SAS Institute 136 | -------------------------------------------------------------------------------- /man/cas.readRDS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_write.R 3 | \name{cas.readRDS} 4 | \alias{cas.readRDS} 5 | \title{Read an RDS File and Upload to a CAS Table} 6 | \usage{ 7 | cas.readRDS( 8 | conn, 9 | file, 10 | refhook = NULL, 11 | casOut = list(name = "", replace = FALSE) 12 | ) 13 | } 14 | \arguments{ 15 | \item{conn}{An instance of a CAS object that represents 16 | a connection and CAS session.} 17 | 18 | \item{file}{An \code{character} string that 19 | specifies the filename for the RDS file. 20 | This value is passed to \code{readRDS}.} 21 | 22 | \item{refhook}{An optional value that is passed to 23 | \code{readRDS}.} 24 | 25 | \item{casOut}{An optional \code{character} or list. If 26 | you specify a string, then the string is used as the 27 | in-memory table name. A list can be used to specify 28 | properties for the in-memory table as follows: 29 | \describe{ 30 | \item{\code{name}}{An optional \code{character} that 31 | specifies the name for the in-memory table. By 32 | default, the name of the data frame is used.} 33 | \item{\code{caslib}}{An optional \code{character} that 34 | specifies the caslib. Specify this parameter to 35 | override the active caslib.} 36 | \item{\code{label}}{An optional \code{character} that 37 | specifies a descriptive label for the data.} 38 | \item{\code{replace}}{An optional \code{logical}. When 39 | set to TRUE, you can replace an existing in-memory 40 | table with the same name in the same caslib. The 41 | default value is FALSE.} 42 | \item{\code{promote}}{An optional \code{logical}. When 43 | set to TRUE, the in-memory table has global scope and 44 | can be available to other CAS sessions (subject to 45 | access controls). The default value is FALSE and 46 | the in-memory table has session scope so that it is 47 | accessible with the session that uploaded the table 48 | only. Session-scope tables are ideal for data analysis. 49 | Global-scope tables are better suited for reporting.} 50 | \item{\code{replication}}{An optional \code{numeric} that 51 | specifies the number of redundant copies of in-memory 52 | blocks. This parameter applies to distributed servers 53 | only. The default value is 1.} 54 | }} 55 | } 56 | \value{ 57 | \code{\link{CASTable}} 58 | } 59 | \description{ 60 | This function is a convenience wrapper for 61 | the \R \code{readRDS} and \code{as.casTable} functions. 62 | After reading the file that is accessible to the \R 63 | client, it is uploaded to an in-memory table in 64 | CAS (the server). 65 | } 66 | \examples{ 67 | \dontrun{ 68 | myCasTable <- cas.readRDS(s, file="/path/to/data_out.rds", 69 | casOut=list(name="mycastable")) 70 | } 71 | } 72 | \seealso{ 73 | Other functions for loading in-memory data: 74 | \code{\link{cas.read.csv}()}, 75 | \code{\link{cas.read.jmp}()}, 76 | \code{\link{cas.read.sas7bdat}()}, 77 | \code{\link{cas.read.table}()}, 78 | \code{\link{cas.read.xlsx}()} 79 | } 80 | \concept{functions for loading in-memory data} 81 | % Copyright SAS Institute 82 | -------------------------------------------------------------------------------- /man/cas.saveRDS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_write.R 3 | \name{cas.saveRDS} 4 | \alias{cas.saveRDS} 5 | \title{Write a CAS Table to RDS} 6 | \usage{ 7 | cas.saveRDS( 8 | CASTable, 9 | file = "", 10 | ascii = FALSE, 11 | version = NULL, 12 | compress = TRUE, 13 | refhook = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{CASTable}{The instance of the CASTable to save as 18 | as an RDS file.} 19 | 20 | \item{file}{An \code{character} string that 21 | specifies the filename for the RDS file. If you do not 22 | specify the file, then the in-memory table name is used 23 | with an .rds suffix. This value is passed to \code{saveRDS}.} 24 | 25 | \item{ascii}{An optional \code{logical} value. When set to 26 | TRUE or NA, then an ASCII representation is written. 27 | Otherwise, a binary is written. This value is passed to 28 | \code{saveRDS}.} 29 | 30 | \item{version}{An optional \code{numeric} value. This value 31 | is passed to \code{saveRDS}.} 32 | 33 | \item{compress}{An optional \code{logical} value. When set 34 | to one of TRUE, "gzip", "bzip2", or "xz", then compression is 35 | used. TRUE performs gzip. This value is passed to \code{saveRDS}.} 36 | 37 | \item{refhook}{An optional value that is passed to 38 | \code{saveRDS}.} 39 | } 40 | \description{ 41 | This function downloads an in-memory table from the 42 | CAS server and saves it as an RDS file that is accessible 43 | to \R (the client). This function is a convenience 44 | wrapper for the \R \code{saveRDS} function. 45 | } 46 | \examples{ 47 | \dontrun{ 48 | cas.saveRDS(myCasTable, file="/path/to/data_out.rds") 49 | } 50 | } 51 | \seealso{ 52 | Other functions for saving in-memory data: 53 | \code{\link{cas.write.csv}()}, 54 | \code{\link{cas.write.table}()}, 55 | \code{\link{cas.write.xlsx}()} 56 | } 57 | \concept{functions for saving in-memory data} 58 | % Copyright SAS Institute 59 | -------------------------------------------------------------------------------- /man/cas.sd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.sd} 4 | \alias{cas.sd} 5 | \title{Standard Deviation} 6 | \usage{ 7 | cas.sd(CASTable, na.rm = TRUE) 8 | } 9 | \arguments{ 10 | \item{na.rm}{An optional \code{logical}. When set to FALSE, 11 | missing values (NA) are not removed from the analysis. 12 | By default, missing values are ignored.} 13 | 14 | \item{x}{CASTable.} 15 | } 16 | \value{ 17 | casDataFrame 18 | 19 | The result includes one row for each numeric variable 20 | and a column that is named Std for the standard deviation. 21 | } 22 | \description{ 23 | Returns the standard deviation of the values for each 24 | column in the input table. 25 | } 26 | \details{ 27 | This function operates on numeric columns only. 28 | } 29 | \examples{ 30 | \dontrun{ 31 | cas.sd(ct[1:4]) 32 | cas.sd(ct$n2) 33 | } 34 | } 35 | % Copyright SAS Institute 36 | -------------------------------------------------------------------------------- /man/cas.stderr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.stderr} 4 | \alias{cas.stderr} 5 | \title{Standard Error} 6 | \usage{ 7 | cas.stderr(CASTable) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | vector 14 | 15 | The result is a named numeric vector. You can access 16 | the standard error by column name or index. 17 | } 18 | \description{ 19 | Returns the standard error of the values for each 20 | column in the input table. 21 | } 22 | \details{ 23 | This function operates on numeric columns only. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | x <- cas.stderr(irisct) 28 | x['Sepal.Length'] 29 | x[1:2] 30 | } 31 | } 32 | % Copyright SAS Institute 33 | -------------------------------------------------------------------------------- /man/cas.sum.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \docType{methods} 4 | \name{cas.sum} 5 | \alias{cas.sum} 6 | \title{Column Sums} 7 | \usage{ 8 | cas.sum(CASTable) 9 | } 10 | \arguments{ 11 | \item{x}{CASTable.} 12 | } 13 | \value{ 14 | casDataFrame 15 | 16 | The result includes one row for each numeric variable 17 | and a column that is named Sum for the summed value. 18 | } 19 | \description{ 20 | Returns the sum of the values for each column in 21 | the input table. 22 | } 23 | \details{ 24 | This function operates on numeric columns only. 25 | } 26 | \examples{ 27 | \dontrun{ 28 | cas.sum(ct[1:4]) 29 | cas.sum(ct$n2) 30 | } 31 | } 32 | \seealso{ 33 | \code{colSums,CASTable-method} 34 | } 35 | % Copyright SAS Institute 36 | -------------------------------------------------------------------------------- /man/cas.terminate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/swat.R 3 | \name{cas.terminate} 4 | \alias{cas.terminate} 5 | \title{End a CAS session and close the connection} 6 | \usage{ 7 | cas.terminate(conn) 8 | } 9 | \arguments{ 10 | \item{CAS}{The CAS connection object} 11 | } 12 | \description{ 13 | End a CAS session and close the connection 14 | } 15 | -------------------------------------------------------------------------------- /man/cas.tvalue.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.tvalue} 4 | \alias{cas.tvalue} 5 | \title{T-Statistics for Hypothesis Testing} 6 | \usage{ 7 | cas.tvalue(CASTable) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | vector 14 | 15 | The result is a named numeric vector. You can access 16 | the t-statistic by column name or index. 17 | } 18 | \description{ 19 | Returns the t-statistic for the 20 | values for each column in the input table. 21 | } 22 | \details{ 23 | This function operates on numeric columns only. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | x <- cas.tvalue(irisct) 28 | x['Sepal.Length'] 29 | x[1:2] 30 | } 31 | } 32 | % Copyright SAS Institute 33 | -------------------------------------------------------------------------------- /man/cas.upload.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/swat.R 3 | \name{cas.upload} 4 | \alias{cas.upload} 5 | \title{Upload a data.frame or file to a CAS table} 6 | \usage{ 7 | cas.upload(conn, ...) 8 | } 9 | \arguments{ 10 | \item{\dots}{Optional parameters that are passed to the table.loadtable action.} 11 | 12 | \item{CAS}{The CAS connection object} 13 | 14 | \item{data.frame/character}{The data.frame, filename, or URL to upload.} 15 | } 16 | \value{ 17 | \code{list} 18 | } 19 | \description{ 20 | Upload a data.frame or file to a CAS table 21 | } 22 | -------------------------------------------------------------------------------- /man/cas.upload.file.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/swat.R 3 | \name{cas.upload.file} 4 | \alias{cas.upload.file} 5 | \title{Upload a data file to a CAS table} 6 | \usage{ 7 | cas.upload.file(conn, ...) 8 | } 9 | \arguments{ 10 | \item{\dots}{Optional parameters that are passed to the table.loadtable action.} 11 | 12 | \item{CAS}{The CAS connection object} 13 | 14 | \item{character}{The filename to upload} 15 | } 16 | \value{ 17 | \code{\link{CASTable}} 18 | } 19 | \description{ 20 | Upload a data file to a CAS table 21 | } 22 | -------------------------------------------------------------------------------- /man/cas.upload.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/swat.R 3 | \name{cas.upload.frame} 4 | \alias{cas.upload.frame} 5 | \title{Upload a data.frame to a CAS table} 6 | \usage{ 7 | cas.upload.frame(conn, ...) 8 | } 9 | \arguments{ 10 | \item{\dots}{Optional parameters that are passed to the table.loadtable action.} 11 | 12 | \item{CAS}{The CAS connection object} 13 | 14 | \item{data.frame}{The data.frame to upload} 15 | } 16 | \value{ 17 | \code{\link{CASTable}} 18 | } 19 | \description{ 20 | Upload a data.frame to a CAS table 21 | } 22 | -------------------------------------------------------------------------------- /man/cas.uss.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.uss} 4 | \alias{cas.uss} 5 | \title{Uncorrected Sum of Squares} 6 | \usage{ 7 | cas.uss(CASTable) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | vector 14 | 15 | The result is a named numeric vector. You can access 16 | the uncorrected sum of squares by column name or index. 17 | } 18 | \description{ 19 | Returns the uncorrected sum of squares of the 20 | values for each column in the input table. 21 | } 22 | \details{ 23 | This function operates on numeric columns only. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | x <- cas.uss(irisct) 28 | x['Sepal.Length'] 29 | x[1:2] 30 | } 31 | } 32 | % Copyright SAS Institute 33 | -------------------------------------------------------------------------------- /man/cas.var.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \name{cas.var} 4 | \alias{cas.var} 5 | \title{Variance} 6 | \usage{ 7 | cas.var(CASTable) 8 | } 9 | \arguments{ 10 | \item{x}{CASTable.} 11 | } 12 | \value{ 13 | casDataFrame 14 | 15 | The result includes one row for each numeric variable 16 | and a column that is named Var for the variance. 17 | } 18 | \description{ 19 | Returns the variance of the values for each 20 | column in the input table. 21 | } 22 | \details{ 23 | This function operates on numeric columns only. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | cas.var(ct[1:4]) 28 | cas.var(ct$n2) 29 | } 30 | } 31 | % Copyright SAS Institute 32 | -------------------------------------------------------------------------------- /man/cas.write.csv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_write.R 3 | \name{cas.write.csv} 4 | \alias{cas.write.csv} 5 | \title{Write a CAS Table to a CSV File} 6 | \usage{ 7 | cas.write.csv( 8 | CASTable, 9 | file = "", 10 | quote = TRUE, 11 | eol = "\\n", 12 | na = "NA", 13 | row.names = TRUE, 14 | fileEncoding = "" 15 | ) 16 | } 17 | \arguments{ 18 | \item{CASTable}{The instance of the CASTable to save as 19 | as a CSV file.} 20 | 21 | \item{file}{An \code{character} string that 22 | specifies the filename for the CSV file. If you do not 23 | specify the file, then the in-memory table name is used 24 | with a .csv suffix. This value is passed to \code{write.csv}.} 25 | 26 | \item{quote}{An optional \code{logical} value or numeric 27 | vector. This value is passed to \code{write.csv}.} 28 | 29 | \item{eol}{An optional \code{character} string that is used as the 30 | end-of-line character or characters. This value is passed to 31 | \code{write.csv}.} 32 | 33 | \item{na}{An optional \code{character} string to represent 34 | missing values. This value is passed to \code{write.csv}.} 35 | 36 | \item{row.names}{An optional \code{logical} value or a 37 | \code{character} vector of row names. This value is passed to 38 | \code{write.csv}.} 39 | 40 | \item{fileEncoding}{An optional \code{character} string that 41 | specifies the encoding to use for writing the CSV file. This 42 | value is passed to \code{write.csv}.} 43 | 44 | \item{append}{An optional \code{logical} value This value 45 | is passed to \code{write.csv}.} 46 | 47 | \item{sep}{An optional \code{character} that is used to separate 48 | values in the CSV file. This value is passed to \code{write.csv}.} 49 | 50 | \item{dec}{An optional \code{character} to represent the decimal 51 | separator. This value is passed to \code{write.csv}.} 52 | 53 | \item{col.names}{An optional \code{logical} value or a 54 | \code{character} vector of column names. This value is passed 55 | to \code{write.csv}.} 56 | 57 | \item{qmethod}{An optional \code{chracter} string that describes 58 | how to write embedded quotation marks. This value is passed 59 | to \code{write.csv}.} 60 | } 61 | \description{ 62 | This function downloads an in-memory table from the 63 | CAS server and saves it as a CSV file that is accesible 64 | to \R (the client). This function is a convenience 65 | wrapper for the \R \code{write.csv} function. 66 | } 67 | \details{ 68 | This function saves the file on the \R client. As an 69 | alternative, you can use the \code{cas.table.save} 70 | generated function to save a server-side CSV file. 71 | } 72 | \examples{ 73 | \dontrun{ 74 | # upload a SAS data set to an in-memory table 75 | gold_medals <- cas.read.sas7bdat(s, "/path/to/gold_medals.sas7bdat") 76 | 77 | # download the in-memory table as a CSV file 78 | cas.write.csv(gold_medals, "~/gold_medals.csv") 79 | 80 | } 81 | } 82 | \seealso{ 83 | Other functions for saving in-memory data: 84 | \code{\link{cas.saveRDS}()}, 85 | \code{\link{cas.write.table}()}, 86 | \code{\link{cas.write.xlsx}()} 87 | } 88 | \concept{functions for saving in-memory data} 89 | % Copyright SAS Institute 90 | -------------------------------------------------------------------------------- /man/cas.write.csv2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_write.R 3 | \name{cas.write.csv2} 4 | \alias{cas.write.csv2} 5 | \title{Write a CAS Table to a CSV File} 6 | \usage{ 7 | cas.write.csv2( 8 | CASTable, 9 | file = "", 10 | quote = TRUE, 11 | eol = "\\n", 12 | na = "NA", 13 | row.names = TRUE, 14 | fileEncoding = "" 15 | ) 16 | } 17 | \description{ 18 | This function is identical to \code{\link{cas.write.csv}} 19 | except that it wraps the \R \code{write.csv2} function. 20 | The \code{write.csv2} function uses a comma 21 | for the decimal separator and a semicolon for the field 22 | delimiter. 23 | } 24 | % Copyright SAS Institute 25 | -------------------------------------------------------------------------------- /man/cas.write.table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_write.R 3 | \name{cas.write.table} 4 | \alias{cas.write.table} 5 | \title{Write a CAS Table to a Table} 6 | \usage{ 7 | cas.write.table( 8 | CASTable, 9 | file = "", 10 | append = FALSE, 11 | quote = TRUE, 12 | sep = " ", 13 | eol = "\\n", 14 | na = "NA", 15 | dec = ".", 16 | row.names = TRUE, 17 | col.names = TRUE, 18 | qmethod = c("escape", "double"), 19 | fileEncoding = "" 20 | ) 21 | } 22 | \arguments{ 23 | \item{CASTable}{The instance of the CASTable to save as 24 | as a file.} 25 | 26 | \item{file}{An \code{character} string that 27 | specifies the filename for the file. If you do not 28 | specify the file, then the table is printed to the 29 | terminal.} 30 | 31 | \item{append}{An optional \code{logical} value. This value 32 | is passed to \code{write.table}.} 33 | 34 | \item{quote}{An optional \code{logical} value or numeric 35 | vector. This value is passed to \code{write.table}.} 36 | 37 | \item{sep}{An optional \code{character} that is used to separate 38 | values in the file. This value is passed to \code{write.table}.} 39 | 40 | \item{eol}{An optional \code{character} string that is used as the 41 | end-of-line character or characters. This value is passed to 42 | \code{write.table}.} 43 | 44 | \item{na}{An optional \code{character} string to represent 45 | missing values. This value is passed to \code{write.table}.} 46 | 47 | \item{dec}{An optional \code{character} to represent the decimal 48 | separator. This value is passed to \code{write.table}.} 49 | 50 | \item{row.names}{An optional \code{logical} value or a 51 | \code{character} vector of row names. This value is passed to 52 | \code{write.table}.} 53 | 54 | \item{col.names}{An optional \code{logical} value or a 55 | \code{character} vector of column names. This value is passed 56 | to \code{write.table}.} 57 | 58 | \item{qmethod}{An optional \code{chracter} string that describes 59 | how to write embedded quotation marks. This value is passed 60 | to \code{write.table}.} 61 | 62 | \item{fileEncoding}{An optional \code{character} string that 63 | specifies the encoding to use for writing the file. This 64 | value is passed to \code{write.table}.} 65 | } 66 | \description{ 67 | This function downloads an in-memory table from the 68 | CAS server and saves it as a file that is accesible 69 | to \R (the client). This function is a convenience 70 | wrapper for the \R \code{write.table} function. 71 | } 72 | \examples{ 73 | \dontrun{ 74 | # 75 | cas.write.table(myCasTable, file="/path/to/data_out.txt", na="") 76 | } 77 | } 78 | \seealso{ 79 | Other functions for saving in-memory data: 80 | \code{\link{cas.saveRDS}()}, 81 | \code{\link{cas.write.csv}()}, 82 | \code{\link{cas.write.xlsx}()} 83 | } 84 | \concept{functions for saving in-memory data} 85 | % Copyright SAS Institute 86 | -------------------------------------------------------------------------------- /man/cas.write.xlsx.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_write.R 3 | \name{cas.write.xlsx} 4 | \alias{cas.write.xlsx} 5 | \title{Write a CAS Table to a Microsoft Excel Workbook} 6 | \usage{ 7 | cas.write.xlsx( 8 | CASTable, 9 | file = "", 10 | sheetName = "Sheet1", 11 | col.names = TRUE, 12 | row.names = TRUE, 13 | append = FALSE, 14 | showNA = TRUE 15 | ) 16 | } 17 | \arguments{ 18 | \item{CASTable}{The instance of the CASTable to save as 19 | as a CSV file.} 20 | 21 | \item{file}{An \code{character} string that 22 | specifies the filename for the XLSX file. If you do not 23 | specify the file, then the in-memory table name is used 24 | with an .xslx suffix. This value is passed to \code{write.xlsx}.} 25 | 26 | \item{sheetName}{An optional \code{character} string that 27 | specifies the sheet name in the workbook. This value is 28 | passed to \code{write.xlsx}.} 29 | 30 | \item{col.names}{An optional \code{logical} value that specifies 31 | whether column names are included in the workbook. This value 32 | is passed to \code{write.xlsx}.} 33 | 34 | \item{row.names}{An optional \code{logical} value that specifies 35 | whether row names are included in the workbook. This value 36 | is passed to \code{write.xlsx}.} 37 | 38 | \item{append}{An optional \code{logical} value. This value 39 | is passed to \code{write.xlsx}.} 40 | 41 | \item{showNA}{An optional \code{logical} value. This value 42 | is passed to \code{write.xlsx}.} 43 | } 44 | \description{ 45 | This function downloads an in-memory table from the 46 | CAS server and saves it as an XLSX file that is accesible 47 | to \R (the client). This function is a convenience 48 | wrapper for the \R \code{write.xslx} function. 49 | } 50 | \examples{ 51 | \dontrun{ 52 | cas.write.xlsx(myCasTable, file="/path/to/data_out.xlsx") 53 | } 54 | } 55 | \seealso{ 56 | Other functions for saving in-memory data: 57 | \code{\link{cas.saveRDS}()}, 58 | \code{\link{cas.write.csv}()}, 59 | \code{\link{cas.write.table}()} 60 | } 61 | \concept{functions for saving in-memory data} 62 | % Copyright SAS Institute 63 | -------------------------------------------------------------------------------- /man/casDataFrame-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CASdf.R 3 | \docType{class} 4 | \name{casDataFrame-class} 5 | \alias{casDataFrame-class} 6 | \alias{casDataFrame} 7 | \title{CAS Data Frame Class} 8 | \usage{ 9 | casDataFrame( 10 | ..., 11 | name = "", 12 | label = "", 13 | title = "", 14 | attrs = list(), 15 | col.labels = "", 16 | col.formats = "", 17 | col.attrs = list(), 18 | col.sizes = list(), 19 | col.types = "", 20 | col.widths = 0 21 | ) 22 | } 23 | \value{ 24 | casDataFrame 25 | } 26 | \description{ 27 | A casDataFrame is a superset of data.frame. The class is used primarily 28 | by functions within the package to store tabular data from CAS action 29 | results and to associate CAS metadata with the tabular data. 30 | } 31 | \details{ 32 | A casDataFrame instance is a data object in \R (the client). 33 | } 34 | \section{Slots}{ 35 | 36 | \describe{ 37 | \item{\code{name}}{An optional \code{character} string that specifies CAS metadata 38 | for a table name.} 39 | 40 | \item{\code{label}}{An optional \code{character} string that specifies CAS metadata 41 | for a table label.} 42 | 43 | \item{\code{title}}{An optional \code{character} string that specifies CAS metadata 44 | for a table title.} 45 | 46 | \item{\code{attrs}}{An optional \code{list} of key-value pairs the specify 47 | user-defined CAS metadata.} 48 | 49 | \item{\code{col.labels}}{An optional \code{character} string that specifies CAS 50 | metadata for column labels.} 51 | 52 | \item{\code{col.formats}}{An optional \code{character} string that specifies CAS 53 | metadata for column formats.} 54 | 55 | \item{\code{col.attrs}}{An optional \code{list} that specifies CAS metadata for 56 | column attributes.} 57 | 58 | \item{\code{col.sizes}}{An optional \code{list} that specifies CAS metadata for 59 | the number of bytes in the widest row.} 60 | 61 | \item{\code{col.types}}{An optional \code{character} that specifies CAS metadata 62 | for the column data types.} 63 | 64 | \item{\code{col.widths}}{An optional \code{numeric} that specifies CAS metadata 65 | for column widths.} 66 | 67 | \item{\code{df}}{The data.frame to encapsulate in the casDataFrame.} 68 | }} 69 | 70 | \seealso{ 71 | \code{casDataFrame} 72 | } 73 | % Copyright SAS Institute 74 | -------------------------------------------------------------------------------- /man/casFormula.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helper.R 3 | \name{casFormula} 4 | \alias{casFormula} 5 | \title{CAS Function to extract information from an \R formula object} 6 | \usage{ 7 | casFormula(f, ct) 8 | } 9 | \arguments{ 10 | \item{f1}{a formula object} 11 | } 12 | \value{ 13 | list with target and inputs as members 14 | } 15 | \description{ 16 | CAS Function to extract information from an \R formula object 17 | } 18 | \keyword{internal} 19 | % Copyright SAS Institute 20 | -------------------------------------------------------------------------------- /man/casRetrieve.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/action.R 3 | \name{casRetrieve} 4 | \alias{casRetrieve} 5 | \title{Utility function that is run from several exported functions.} 6 | \usage{ 7 | casRetrieve(caz, actn, ...) 8 | } 9 | \description{ 10 | The generated functions, such as cas.table.tableInfo and 11 | cas.decisionTree.dtreeTrain, or runAction are better candidates 12 | for use by programmers. 13 | } 14 | \keyword{internal} 15 | % Copyright SAS Institute 16 | -------------------------------------------------------------------------------- /man/cbind.casTable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/table_functions.R 3 | \name{cbind.casTable} 4 | \alias{cbind.casTable} 5 | \title{Combine CAS Tables by Columns} 6 | \usage{ 7 | \method{cbind}{casTable}(..., deparse.level = 1) 8 | } 9 | \description{ 10 | Combine CAS Tables by Columns 11 | } 12 | % Copyright SAS Institute 13 | -------------------------------------------------------------------------------- /man/cbind2.casTable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/table_functions.R 3 | \docType{methods} 4 | \name{cbind2.casTable} 5 | \alias{cbind2.casTable} 6 | \alias{cbind2,CASTable,ANY-method} 7 | \title{Combine CAS Tables by Columns} 8 | \usage{ 9 | cbind2.casTable(x, y, ...) 10 | 11 | \S4method{cbind2}{CASTable,ANY}(x, y, ...) 12 | } 13 | \arguments{ 14 | \item{\dots}{Arguments that are passed to method arguments.} 15 | 16 | \item{deparse.level}{See the help for base::cbind.} 17 | } 18 | \value{ 19 | \code{\link{CASTable}} 20 | } 21 | \description{ 22 | This is the implementation of \code{cbind} for in-memory tables. 23 | } 24 | \examples{ 25 | \dontrun{ 26 | cbind(ct1, ct2) 27 | cbind(ct1[1:3], ct2$X1) 28 | } 29 | } 30 | % Copyright SAS Institute 31 | -------------------------------------------------------------------------------- /man/colMeans-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \docType{methods} 4 | \name{colMeans,CASTable-method} 5 | \alias{colMeans,CASTable-method} 6 | \title{Column Means} 7 | \usage{ 8 | \S4method{colMeans}{CASTable}(x) 9 | } 10 | \arguments{ 11 | \item{x}{CASTable.} 12 | } 13 | \value{ 14 | vector 15 | } 16 | \description{ 17 | Column Means 18 | } 19 | \examples{ 20 | \dontrun{ 21 | colMeans(ct[1:4]) 22 | colMeans(ct$X1) 23 | } 24 | } 25 | \seealso{ 26 | \code{cas.mean} 27 | } 28 | % Copyright SAS Institute 29 | -------------------------------------------------------------------------------- /man/colSums-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \docType{methods} 4 | \name{colSums,CASTable-method} 5 | \alias{colSums,CASTable-method} 6 | \title{Column Sums} 7 | \usage{ 8 | \S4method{colSums}{CASTable}(x, na.rm = FALSE, dims = 1, ...) 9 | } 10 | \arguments{ 11 | \item{x}{CASTable.} 12 | } 13 | \value{ 14 | vector 15 | } 16 | \description{ 17 | Column Sums 18 | } 19 | \examples{ 20 | \dontrun{ 21 | colSums(ct[1:4]) 22 | colSums(ct$X1) 23 | } 24 | } 25 | \seealso{ 26 | \code{cas.sum} 27 | } 28 | % Copyright SAS Institute 29 | -------------------------------------------------------------------------------- /man/colnames-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \docType{methods} 4 | \name{colnames,CASTable-method} 5 | \alias{colnames,CASTable-method} 6 | \title{Column Names in a CAS Table} 7 | \usage{ 8 | \S4method{colnames}{CASTable}(x) 9 | } 10 | \arguments{ 11 | \item{x}{A CASTable object.} 12 | } 13 | \value{ 14 | vector 15 | } 16 | \description{ 17 | Returns the column names from the in-memory table 18 | that is referenced by the \code{\link{CASTable}} object. 19 | } 20 | \section{Note}{ 21 | 22 | You cannot use this function to set the column names. 23 | } 24 | 25 | \examples{ 26 | \dontrun{ 27 | colnames(ct1) 28 | colnames(ct[1:4]) 29 | } 30 | } 31 | \seealso{ 32 | \code{names,CASTable-method} 33 | } 34 | % Copyright SAS Institute 35 | -------------------------------------------------------------------------------- /man/cor-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \docType{methods} 4 | \name{cor,CASTable-method} 5 | \alias{cor,CASTable-method} 6 | \title{Correlation} 7 | \usage{ 8 | \S4method{cor}{CASTable}(x, y = NULL, use = "everything", method = c("pearson")) 9 | } 10 | \arguments{ 11 | \item{x}{CASTable.} 12 | } 13 | \value{ 14 | matrix 15 | } 16 | \description{ 17 | Unlike the \code{cor} function for data frames, 18 | this function does not support specifying the 19 | method as "kendall" or "spearman." The results 20 | for method "pearson" are returned. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | cor(ct1) 25 | cor(i2[1:4]) 26 | cor(i2[c('col1', 'col2', 'col3')]) 27 | cor(i2$col1, i2$col2) 28 | } 29 | } 30 | % Copyright SAS Institute 31 | -------------------------------------------------------------------------------- /man/cov-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \docType{methods} 4 | \name{cov,CASTable-method} 5 | \alias{cov,CASTable-method} 6 | \title{Covariance} 7 | \usage{ 8 | \S4method{cov}{CASTable}(x, y = NULL, use = "everything", method = c("pearson")) 9 | } 10 | \arguments{ 11 | \item{x}{CASTable.} 12 | } 13 | \value{ 14 | matrix 15 | } 16 | \description{ 17 | Unlike the \code{cov} function for data frames, 18 | this function does not support specifying the 19 | method as "kendall" or "spearman." The results 20 | for method "pearson" are returned. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | cov(ct1) 25 | cov(i2[1:4]) 26 | cov(i2[c('col1', 'col2', 'col3')]) 27 | cov(i2$col1, i2$col2) 28 | } 29 | } 30 | % Copyright SAS Institute 31 | -------------------------------------------------------------------------------- /man/defCasTable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \name{defCasTable} 4 | \alias{defCasTable} 5 | \title{Create a CASTable Object for an Existing CAS Table} 6 | \usage{ 7 | defCasTable( 8 | conn, 9 | tablename, 10 | caslib = "", 11 | columns = "", 12 | where = "", 13 | orderby = list(), 14 | groupby = list(), 15 | gbmode = "" 16 | ) 17 | } 18 | \arguments{ 19 | \item{conn}{A \code{\link{CAS}} object that represents 20 | a connection and session in CAS.} 21 | 22 | \item{tablename}{A \code{character} that specifies the in-memory 23 | table name. You can run the cas.table.tableInfo function to 24 | list the in-memory tables.} 25 | 26 | \item{caslib}{An optional \code{character} string that 27 | identifies the caslib for the in-memory table. Specify 28 | this parameter to override the active caslib.} 29 | 30 | \item{columns}{A \code{list} of column names.} 31 | 32 | \item{where}{A \code{character} string that specifies a filter for the 33 | rows to process. The filter uses syntax that is specific to SAS.} 34 | 35 | \item{orderby}{A \code{list} of column names. Rows are partitioned according 36 | to the columns in the groupby parameter and then ordered according to 37 | the values of the columns specified in this parameter.} 38 | 39 | \item{groupby}{A \code{list} of column names. If you specify this parameter 40 | when you load an in-memory table, then the table is partitioned by the 41 | columns. If you specify this parameter when running an action, then 42 | BY-groups are formed temporarily for the duration of the action.} 43 | 44 | \item{gbmode}{A \code{character} string. Values are NOSORT (default) or 45 | REDISTRIBUTE. See the CAS product documentation for more information.} 46 | } 47 | \value{ 48 | \code{\link{CASTable}} 49 | } 50 | \description{ 51 | Creates a \code{\link{CASTable}} object to reference 52 | an existing in-memory table in CAS. You can use this 53 | function to reference tables that were loaded by other 54 | SAS products, other scripts, or from server-side loads 55 | with the cas.table.loadTable function. 56 | } 57 | \examples{ 58 | \dontrun{ 59 | irisct <- as.casTable(s, iris, casOut="irisct") 60 | 61 | # Create another CASTable instance to the same in-memory table, 62 | # but specify that CAS actions are performed by groups of species. 63 | irisct.grouped <- defCasTable(s, tablename="irisct", groupby=list("species")) 64 | } 65 | } 66 | % Copyright SAS Institute 67 | -------------------------------------------------------------------------------- /man/dim-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \docType{methods} 4 | \name{dim,CASTable-method} 5 | \alias{dim,CASTable-method} 6 | \title{Dimensions of a CAS Table} 7 | \usage{ 8 | \S4method{dim}{CASTable}(x) 9 | } 10 | \arguments{ 11 | \item{x}{A CASTable object.} 12 | } 13 | \value{ 14 | vector 15 | } 16 | \description{ 17 | Returns the number of rows and columns for the in-memory 18 | table that is referenced by the \code{\link{CASTable}} object. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | dim(ct1) 23 | } 24 | } 25 | % Copyright SAS Institute 26 | -------------------------------------------------------------------------------- /man/dimnames-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \docType{methods} 4 | \name{dimnames,CASTable-method} 5 | \alias{dimnames,CASTable-method} 6 | \title{Dimension Names of a CAS Table} 7 | \usage{ 8 | \S4method{dimnames}{CASTable}(x) 9 | } 10 | \arguments{ 11 | \item{x}{A \code{\link{CASTable}} object.} 12 | } 13 | \value{ 14 | list 15 | } 16 | \description{ 17 | Dimension Names of a CAS Table 18 | } 19 | \examples{ 20 | \dontrun{ 21 | dimnames(ct1) 22 | dimnames(ct[2:4]) 23 | } 24 | } 25 | % Copyright SAS Institute 26 | -------------------------------------------------------------------------------- /man/dropTable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \name{dropTable} 4 | \alias{dropTable} 5 | \title{Remove a CAS Table} 6 | \usage{ 7 | dropTable(x) 8 | } 9 | \arguments{ 10 | \item{x}{A CASTable object.} 11 | } 12 | \description{ 13 | Drops the in-memory table on the server that is 14 | referenced by the \code{\link{CASTable}} object. 15 | } 16 | \section{Note}{ 17 | 18 | This function drops the in-memory table but does 19 | not affect the original source file that the 20 | in-memory table was loaded from. 21 | } 22 | 23 | \examples{ 24 | \dontrun{ 25 | dropTable(ct1) 26 | } 27 | } 28 | % Copyright SAS Institute 29 | -------------------------------------------------------------------------------- /man/head-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/table_functions.R 3 | \docType{methods} 4 | \name{head,CASTable-method} 5 | \alias{head,CASTable-method} 6 | \title{Return the First Part of a CAS Table} 7 | \usage{ 8 | \S4method{head}{CASTable}(x, n = 6L) 9 | } 10 | \arguments{ 11 | \item{x}{A CASTable object.} 12 | 13 | \item{n}{An optional positive integer that specifies the number of 14 | rows to return.} 15 | } 16 | \value{ 17 | A \code{\link{casDataFrame}} object with the first n rows. 18 | } 19 | \description{ 20 | Returns the first part of an in-memory table that is referenced 21 | by a \code{\link{CASTable}} object. 22 | } 23 | \section{Note}{ 24 | 25 | 26 | The \code{head} function is not deterministic between reloads of data 27 | or if nodes or added or removed from a distributed server. 28 | } 29 | 30 | \examples{ 31 | \dontrun{ 32 | head(ct1) 33 | head(ct[1:4], 10) 34 | } 35 | } 36 | % Copyright SAS Institute 37 | -------------------------------------------------------------------------------- /man/is.castable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \name{is.castable} 4 | \alias{is.castable} 5 | \title{Test if an Object is a CAS Table} 6 | \usage{ 7 | is.castable(x) 8 | } 9 | \arguments{ 10 | \item{x}{An \code{R} object.} 11 | } 12 | \value{ 13 | boolean 14 | } 15 | \description{ 16 | Test if an Object is a CAS Table 17 | } 18 | \examples{ 19 | \dontrun{ 20 | is.castable(ct1) # TRUE 21 | is.castable(iris) # FALSE 22 | } 23 | } 24 | % Copyright SAS Institute 25 | -------------------------------------------------------------------------------- /man/length-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \docType{methods} 4 | \name{length,CASTable-method} 5 | \alias{length,CASTable-method} 6 | \title{Number of Columns in a CAS Table} 7 | \usage{ 8 | \S4method{length}{CASTable}(x) 9 | } 10 | \arguments{ 11 | \item{x}{A CASTable object.} 12 | } 13 | \value{ 14 | scalar 15 | } 16 | \description{ 17 | Returns the number of columns in an in-memory table 18 | that is referenced by the \code{\link{CASTable}} object. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | length(ct1) 23 | length(ct[1:4]) 24 | } 25 | } 26 | \seealso{ 27 | \code{ncol,CASTable-method} 28 | } 29 | % Copyright SAS Institute 30 | -------------------------------------------------------------------------------- /man/listActionParms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/action.R 3 | \name{listActionParms} 4 | \alias{listActionParms} 5 | \title{List CAS Action Parameters by Name} 6 | \usage{ 7 | listActionParms(conn, actn, display = TRUE) 8 | } 9 | \arguments{ 10 | \item{conn}{An instance of a CAS object that represents 11 | a connection and CAS session.} 12 | 13 | \item{actn}{A \code{string} value that specifies 14 | the action name. You can specify the following forms: 15 | \itemize{ 16 | \item \emph{action-set.action-name} 17 | \item \emph{action-name} 18 | \item cas.\emph{action-set.action-name} 19 | } 20 | The third form matches the generated functions for 21 | the CAS actions.} 22 | 23 | \item{display}{Should the parameters be printed to the 24 | screen?} 25 | } 26 | \description{ 27 | This function displays the parameters for the specified 28 | CAS action. 29 | } 30 | \examples{ 31 | \dontrun{ 32 | # specify the action set and action name 33 | listActionParms(conn, actn="simple.summary") 34 | 35 | # fetch is in the table action set 36 | listActionParms(s, actn="fetch") 37 | 38 | # specify the generated function name 39 | listActionParms(s, cas.regression.logistic) 40 | } 41 | } 42 | % Copyright SAS Institute 43 | -------------------------------------------------------------------------------- /man/listActionSets.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/action.R 3 | \name{listActionSets} 4 | \alias{listActionSets} 5 | \title{List CAS Action Sets} 6 | \usage{ 7 | listActionSets(conn) 8 | } 9 | \arguments{ 10 | \item{conn}{An instance of a CAS object that represents 11 | a connection and CAS session.} 12 | } 13 | \description{ 14 | This function lists all action sets that are installed on the 15 | CAS server. The results include a column that is named loaded 16 | to indicate if the action set is already available for use 17 | or must be loaded before it can be used. 18 | } 19 | \examples{ 20 | \dontrun{ 21 | listActionSets(conn) 22 | } 23 | 24 | } 25 | % Copyright SAS Institute 26 | -------------------------------------------------------------------------------- /man/loadActionSet.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/action.R 3 | \name{loadActionSet} 4 | \alias{loadActionSet} 5 | \title{Load a CAS Action Set} 6 | \usage{ 7 | loadActionSet(conn, actionSet = "") 8 | } 9 | \arguments{ 10 | \item{conn}{An instance of a CAS object that represents 11 | a connection and CAS session.} 12 | 13 | \item{actionSet}{A \code{string} value that specifies 14 | the action set to load.} 15 | } 16 | \description{ 17 | This function loads a CAS action set and generate an \R function 18 | for each action. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | loadActionSet(conn, actionSet="decisionTree") 23 | loadActionSet(conn, actionSet="regression") 24 | } 25 | } 26 | % Copyright SAS Institute 27 | -------------------------------------------------------------------------------- /man/max-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \docType{methods} 4 | \name{max,CASTable-method} 5 | \alias{max,CASTable-method} 6 | \title{Maximum Values} 7 | \usage{ 8 | \S4method{max}{CASTable}(x) 9 | } 10 | \arguments{ 11 | \item{x}{CASTable.} 12 | } 13 | \value{ 14 | scalar 15 | } 16 | \description{ 17 | Maximum Values 18 | } 19 | \examples{ 20 | \dontrun{ 21 | max(ct1$X1) 22 | max(ct1[1:2]) 23 | } 24 | } 25 | \seealso{ 26 | \code{cas.max} 27 | } 28 | % Copyright SAS Institute 29 | -------------------------------------------------------------------------------- /man/mean-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \docType{methods} 4 | \name{mean,CASTable-method} 5 | \alias{mean,CASTable-method} 6 | \title{Mean Value for a Single Column} 7 | \usage{ 8 | \S4method{mean}{CASTable}(x, ...) 9 | } 10 | \arguments{ 11 | \item{x}{CASTable.} 12 | } 13 | \value{ 14 | scalar 15 | } 16 | \description{ 17 | Returns the mean value for the specified column in 18 | the input table. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | mean(ct1$x1) 23 | mean(ct1[2]) 24 | } 25 | } 26 | \seealso{ 27 | \code{cas.mean} 28 | } 29 | % Copyright SAS Institute 30 | -------------------------------------------------------------------------------- /man/median-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \docType{methods} 4 | \name{median,CASTable-method} 5 | \alias{median,CASTable-method} 6 | \title{Median Values} 7 | \usage{ 8 | \S4method{median}{CASTable}(x) 9 | } 10 | \arguments{ 11 | \item{x}{CASTable.} 12 | } 13 | \value{ 14 | scalar 15 | } 16 | \description{ 17 | Median Values 18 | } 19 | \examples{ 20 | \dontrun{ 21 | median(ct1$x1) 22 | median(ct1[1:4]) 23 | } 24 | } 25 | \seealso{ 26 | \code{cas.median} 27 | } 28 | % Copyright SAS Institute 29 | -------------------------------------------------------------------------------- /man/min-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \docType{methods} 4 | \name{min,CASTable-method} 5 | \alias{min,CASTable-method} 6 | \title{Minimum Value} 7 | \usage{ 8 | \S4method{min}{CASTable}(x) 9 | } 10 | \arguments{ 11 | \item{x}{CASTable.} 12 | } 13 | \value{ 14 | scalar 15 | } 16 | \description{ 17 | Minimum Value 18 | } 19 | \examples{ 20 | \dontrun{ 21 | min(ct1$X1) 22 | min(ct1[1:2]) 23 | } 24 | } 25 | \seealso{ 26 | \code{cas.min} 27 | } 28 | % Copyright SAS Institute 29 | -------------------------------------------------------------------------------- /man/names-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \docType{methods} 4 | \name{names,CASTable-method} 5 | \alias{names,CASTable-method} 6 | \title{Names of a CAS Table} 7 | \usage{ 8 | \S4method{names}{CASTable}(x) 9 | } 10 | \arguments{ 11 | \item{x}{A CASTable object.} 12 | } 13 | \value{ 14 | vector 15 | } 16 | \description{ 17 | Returns the list of column names for the in-memory 18 | table that is referenced by the \code{\link{CASTable}} object. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | names(ct1) 23 | } 24 | } 25 | % Copyright SAS Institute 26 | -------------------------------------------------------------------------------- /man/ncol-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \docType{methods} 4 | \name{ncol,CASTable-method} 5 | \alias{ncol,CASTable-method} 6 | \title{Number of Columns in a CAS Table} 7 | \usage{ 8 | \S4method{ncol}{CASTable}(x) 9 | } 10 | \arguments{ 11 | \item{x}{A CASTable object.} 12 | } 13 | \value{ 14 | scalar 15 | } 16 | \description{ 17 | Returns the number of columns in an in-memory table 18 | that is referenced by the \code{\link{CASTable}} object. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | ncol(ct1) 23 | ncol(ct[1:4]) 24 | } 25 | } 26 | \seealso{ 27 | \code{length,CASTable-method} 28 | } 29 | % Copyright SAS Institute 30 | -------------------------------------------------------------------------------- /man/nrow-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \docType{methods} 4 | \name{nrow,CASTable-method} 5 | \alias{nrow,CASTable-method} 6 | \title{Number of Rows in a CAS Table} 7 | \usage{ 8 | \S4method{nrow}{CASTable}(x) 9 | } 10 | \arguments{ 11 | \item{x}{A CASTable object.} 12 | } 13 | \value{ 14 | scalar 15 | } 16 | \description{ 17 | Returns the number of rows in an in-memory table 18 | that is referenced by the \code{\link{CASTable}} object. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | nrow(ct1) 23 | nrow(ct[1:4]) 24 | } 25 | } 26 | % Copyright SAS Institute 27 | -------------------------------------------------------------------------------- /man/rbind-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/table_functions.R 3 | \docType{methods} 4 | \name{rbind,CASTable-method} 5 | \alias{rbind,CASTable-method} 6 | \title{Combine CAS Tables by Rows} 7 | \usage{ 8 | \S4method{rbind}{CASTable}(..., deparse.level = 1) 9 | } 10 | \arguments{ 11 | \item{\dots}{Arguments that are passed to method arguments.} 12 | 13 | \item{deparse.level}{See the help for base::rbind.} 14 | } 15 | \value{ 16 | \code{\link{CASTable}} 17 | } 18 | \description{ 19 | This is the implementation of rbind for in-memory tables. 20 | } 21 | \examples{ 22 | \dontrun{ 23 | rbind(ct1,ct2) 24 | rbind(ct1,ct2, ct3) 25 | } 26 | } 27 | % Copyright SAS Institute 28 | -------------------------------------------------------------------------------- /man/rbind.casTable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/table_functions.R 3 | \name{rbind.casTable} 4 | \alias{rbind.casTable} 5 | \title{Combine CAS Tables by Columns} 6 | \usage{ 7 | rbind.casTable(..., deparse.level = 1) 8 | } 9 | \description{ 10 | Combine CAS Tables by Columns 11 | } 12 | % Copyright SAS Institute 13 | -------------------------------------------------------------------------------- /man/rbind2.casTable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/table_functions.R 3 | \docType{methods} 4 | \name{rbind2.casTable} 5 | \alias{rbind2.casTable} 6 | \alias{rbind2,CASTable,ANY-method} 7 | \title{Combine CAS Tables by Rows} 8 | \usage{ 9 | rbind2.casTable(x, y, ...) 10 | 11 | \S4method{rbind2}{CASTable,ANY}(x, y, ...) 12 | } 13 | \arguments{ 14 | \item{\dots}{Arguments that are passed to method arguments.} 15 | 16 | \item{deparse.level}{See the help for base::rbind.} 17 | } 18 | \value{ 19 | \code{\link{CASTable}} 20 | } 21 | \description{ 22 | This is the implementation of \code{rbind} for in-memory tables. 23 | } 24 | \examples{ 25 | \dontrun{ 26 | rbind(ct1,ct2) 27 | rbind(ct1,ct2, ct3) 28 | } 29 | } 30 | % Copyright SAS Institute 31 | -------------------------------------------------------------------------------- /man/rownames-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \docType{methods} 4 | \name{rownames,CASTable-method} 5 | \alias{rownames,CASTable-method} 6 | \title{Row Names of a CAS Table} 7 | \usage{ 8 | \S4method{rownames}{CASTable}(x) 9 | } 10 | \arguments{ 11 | \item{x}{A \code{\link{CASTable}} object.} 12 | } 13 | \value{ 14 | list of strings 15 | } 16 | \description{ 17 | Row Names of a CAS Table 18 | } 19 | \examples{ 20 | \dontrun{ 21 | rownames(ct1) 22 | rownames(ct[2:4]) 23 | } 24 | } 25 | % Copyright SAS Institute 26 | -------------------------------------------------------------------------------- /man/runAction.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/action.R 3 | \name{runAction} 4 | \alias{runAction} 5 | \title{Run a CAS Action by Name} 6 | \usage{ 7 | runAction(CASorCASTab = "", actn, check_errors = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{CASorCASTab}{An instance of a CAS object that represents 11 | a connection and CAS session, or an instance of a CASTable.} 12 | 13 | \item{actn}{A \code{character} string that specifies 14 | the action set and action name to run.} 15 | 16 | \item{\dots}{Parameters that are passed to the CAS action.} 17 | } 18 | \description{ 19 | This function enables you to specify a CAS action 20 | name and run it. This is an alternative to running 21 | an action from the generated function names. An 22 | example of a generated function name is cas.table.tableInfo. 23 | } 24 | \examples{ 25 | \dontrun{ 26 | # display the active caslib for the session 27 | runAction(conn, "sessionProp.getSessOpt", name="caslib") 28 | 29 | # display simple summary statistics for an uploaded data frame 30 | mtcarsct <- as.casTable(conn, mtcars) 31 | runAction(mtcarsct, "simple.summary") 32 | 33 | # the preceding runAction function is functionally 34 | # equivalent to the following generated function 35 | cas.simple.summary(mtcarsct) 36 | } 37 | 38 | } 39 | % Copyright SAS Institute 40 | -------------------------------------------------------------------------------- /man/show-casDataFrame-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CASdf.R 3 | \docType{methods} 4 | \name{show,casDataFrame-method} 5 | \alias{show,casDataFrame-method} 6 | \title{CAS data frame show method} 7 | \usage{ 8 | \S4method{show}{casDataFrame}(object) 9 | } 10 | \arguments{ 11 | \item{object}{A \code{casDataFrame} object.} 12 | } 13 | \value{ 14 | data frame listing 15 | } 16 | \description{ 17 | CAS data frame show method 18 | } 19 | % Copyright SAS Institute 20 | -------------------------------------------------------------------------------- /man/subset.casTable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/table_functions.R 3 | \name{subset.casTable} 4 | \alias{subset.casTable} 5 | \title{Return a Subset of Rows and Columns from a CAS Table} 6 | \usage{ 7 | subset.casTable(x, subset, select = NULL, drop = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A CASTable object.} 11 | } 12 | \value{ 13 | A CASTable object with the rows and columns that meet the subset criteria. 14 | } 15 | \description{ 16 | Return a subset of rows and columns from a \code{\link{CASTable}} that meet 17 | subsetting criteria. 18 | } 19 | \examples{ 20 | \dontrun{ 21 | subset(ct, subset = ct[4] > 15, select = c("n1", "n4", "s"), drop = FALSE) 22 | subset(ct, subset = ct$n4 > 15, select = c(1, 4, 5), drop = FALSE) 23 | } 24 | } 25 | % Copyright SAS Institute 26 | -------------------------------------------------------------------------------- /man/summary-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/descriptive_stats.R 3 | \docType{methods} 4 | \name{summary,CASTable-method} 5 | \alias{summary,CASTable-method} 6 | \title{Summary Statistics} 7 | \usage{ 8 | \S4method{summary}{CASTable}(object, maxsum = 7, digits = max(3, getOption("digits") - 3), ...) 9 | } 10 | \arguments{ 11 | \item{object}{CASTable.} 12 | } 13 | \value{ 14 | table 15 | } 16 | \description{ 17 | Returns simple descriptive statistics. 18 | } 19 | \examples{ 20 | \dontrun{ 21 | summary(ct1) 22 | summary(ct1[1:4]) 23 | } 24 | } 25 | % Copyright SAS Institute 26 | -------------------------------------------------------------------------------- /man/swat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/swat.R 3 | \docType{package} 4 | \name{swat} 5 | \alias{swat} 6 | \alias{swat-package} 7 | \title{SWAT: SAS Wrapper for Analytics Transfer (SWAT)} 8 | \description{ 9 | This package enables you to connect from \R to a SAS Cloud Analytic Services 10 | host, run actions on in-memory tables, and work with the results of the 11 | actions. 12 | \itemize{ 13 | \item The \code{\link{CAS}} class provides an interface to your 14 | connection to the CAS server and CAS session. 15 | \item The \code{\link{CASTable}} class provides an interface to the 16 | in-memory tables. 17 | \item The \code{\link{casDataFrame}} class provides an interface 18 | to the results for most actions. 19 | } 20 | } 21 | \details{ 22 | Depending on how you install the package, you might be able to use binary 23 | communication with CAS. This is more efficient for bandwidth, but requires 24 | that your \R installation have access to a precompiled library (rswat.so or 25 | rswat.dll). An alternative is to communicate with the server using the REST 26 | interface of the server over HTTP. See the connection examples that follow. 27 | 28 | The responses and results of the actions are returned as \R objects. 29 | } 30 | \section{Connect and start a session}{ 31 | 32 | \preformatted{ 33 | s <- CAS('cloud.example.com', 5570) # binary communication 34 | 35 | s2 <- CAS('cloud.example.com', 8777, protocol='https') 36 | } 37 | } 38 | 39 | \section{Run a simple action}{ 40 | 41 | \preformatted{ 42 | results <- runAction(s, "builtins.serverStatus") 43 | results$server 44 | nodes actions 45 | 1 1 15 46 | } 47 | 48 | You can also run an action using the generated \R function: 49 | \preformatted{ 50 | results <- cas.builtins.serverStatus(s) 51 | results$server 52 | nodes actions 53 | 1 1 15 54 | } 55 | } 56 | 57 | \section{Upload a data.frame to a CASTable}{ 58 | 59 | \preformatted{ 60 | irisct <- as.casTable(s, iris) 61 | } 62 | } 63 | 64 | \section{Load a CAS actionSet}{ 65 | 66 | \preformatted{ 67 | runAction(s, "builtins.loadActionSet", actionSet="regression") 68 | } 69 | } 70 | 71 | \section{Useful links}{ 72 | 73 | \itemize{ 74 | \item{\url{http://developer.sas.com/guides/r.html}} 75 | \item{\url{https://github.com/sassoftware/r-swat}} 76 | \item{Enter issues at \url{https://github.com/sassoftware/r-swat/issues}} 77 | } 78 | } 79 | 80 | \section{Action documentation}{ 81 | 82 | See the \href{http://documentation.sas.com/?softwareId=pgm 83 | &softwareVersion=production.a&softwareContextId=allProdsActions&showBanner=develop}{ 84 | Actions and Action Sets by Name and Product} 85 | } 86 | 87 | \author{ 88 | \strong{Maintainer}: Jared Dean \email{Jared.Dean@sas.com} 89 | 90 | Authors: 91 | \itemize{ 92 | \item Tom Weber \email{Tom.Weber@sas.com} 93 | \item Kevin Smith \email{Kevin.Smith@sas.com} 94 | } 95 | 96 | } 97 | % Copyright SAS Institute 98 | -------------------------------------------------------------------------------- /man/tail-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/table_functions.R 3 | \docType{methods} 4 | \name{tail,CASTable-method} 5 | \alias{tail,CASTable-method} 6 | \title{Return the Last Part of a CAS Table} 7 | \usage{ 8 | \S4method{tail}{CASTable}(x, n = 6L) 9 | } 10 | \arguments{ 11 | \item{x}{A CASTable object.} 12 | } 13 | \value{ 14 | A \code{\link{casDataFrame}} object with the last n rows. 15 | } 16 | \description{ 17 | Returns the last part of an in-memory table that is referenced 18 | by a \code{\link{CASTable}} object. 19 | } 20 | \section{Note}{ 21 | 22 | 23 | The \code{tail} function is not deterministic between reloads of data 24 | or if nodes or added or removed from a distributed server. 25 | } 26 | 27 | \examples{ 28 | \dontrun{ 29 | tail(ct1) 30 | tail(ct[1:4], 10) 31 | } 32 | } 33 | % Copyright SAS Institute 34 | -------------------------------------------------------------------------------- /man/to.casDataFrame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CASdf.R 3 | \name{to.casDataFrame} 4 | \alias{to.casDataFrame} 5 | \title{Convert a CAS Table to a CAS Data Frame (Download)} 6 | \usage{ 7 | to.casDataFrame(ct, obs = 32768) 8 | } 9 | \arguments{ 10 | \item{ct}{The CASTable object to download.} 11 | } 12 | \value{ 13 | Returns a casDataFrame object that contains 14 | a copy of the in-memory data. 15 | } 16 | \description{ 17 | Downloads the in-memory table that is referenced by 18 | the CASTable object and stores it as a casDataFrame 19 | in R. This function is used primarily by the package 20 | to store the results of a CAS action. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | cdf = to.casDataFrame(CASTable) 25 | } 26 | } 27 | % Copyright SAS Institute 28 | -------------------------------------------------------------------------------- /man/to.data.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CASdf.R 3 | \name{to.data.frame} 4 | \alias{to.data.frame} 5 | \title{Convert a CAS data frame to an \R Data Frame} 6 | \usage{ 7 | to.data.frame(cdf) 8 | } 9 | \arguments{ 10 | \item{cdf}{The casDataFrame to convert} 11 | } 12 | \value{ 13 | Data Frame 14 | } 15 | \description{ 16 | This function returns the \R data.frame object that is encapsulated 17 | in a casDataFrame. The CAS metadata is not available in the returned 18 | data.frame. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | df3 = to.data.frame(cdf) 23 | } 24 | } 25 | % Copyright SAS Institute 26 | -------------------------------------------------------------------------------- /man/to.r.data.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CAStab.R 3 | \name{to.r.data.frame} 4 | \alias{to.r.data.frame} 5 | \title{Convert a CAS Table to a R Data Frame (Download)} 6 | \usage{ 7 | to.r.data.frame(ct, obs = 32768) 8 | } 9 | \arguments{ 10 | \item{ct}{The CASTable object to download.} 11 | 12 | \item{obs}{Number of rows to download, by default 32768} 13 | } 14 | \value{ 15 | Returns a data.frame object that contains 16 | a copy of the in-memory data. 17 | } 18 | \description{ 19 | Downloads the in-memory table that is referenced by 20 | the CASTable object and stores it as a data.frame 21 | in R. This function is used to download datasets from CAS. 22 | } 23 | \examples{ 24 | \dontrun{ 25 | rdf = to.r.data.frame(CASTable) 26 | } 27 | 28 | } 29 | % Copyright SAS Institute 30 | -------------------------------------------------------------------------------- /man/unique-CASTable-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/table_functions.R 3 | \docType{methods} 4 | \name{unique,CASTable-method} 5 | \alias{unique,CASTable-method} 6 | \title{Extract Unique Values from a CAS Table} 7 | \usage{ 8 | \S4method{unique}{CASTable}(x, incomparables = FALSE, ...) 9 | } 10 | \arguments{ 11 | \item{x}{A CASTable object.} 12 | 13 | \item{incomparables}{A vector of values that cannot be compared. 14 | See the help for base::unique.} 15 | 16 | \item{\dots}{Arguments that are passed to method arguments.} 17 | } 18 | \value{ 19 | A \code{\link{casDataFrame}} object. 20 | } 21 | \description{ 22 | Extracts distinct values from columns in a \code{\link{CASTable}}. 23 | } 24 | \examples{ 25 | \dontrun{ 26 | unique(ct[4:5]) 27 | unique(ct$s) 28 | unique(ct[4]) 29 | } 30 | } 31 | % Copyright SAS Institute 32 | -------------------------------------------------------------------------------- /tests/data/census2.sas7bdat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/R-swat/847881dad284574ba3438b39db68a17b42e5d09e/tests/data/census2.sas7bdat -------------------------------------------------------------------------------- /tests/data/class.csv: -------------------------------------------------------------------------------- 1 | Name,Sex,Age,Height,Weight 2 | Alfred,M,14,69,112.5 3 | Alice,F,13,56.5,84 4 | Barbara,F,13,65.3,98 5 | Carol,F,14,62.8,102.5 6 | Henry,M,14,63.5,102.5 7 | James,M,12,57.3,83 8 | Jane,F,12,59.8,84.5 9 | Janet,F,15,62.5,112.5 10 | Jeffrey,M,13,62.5,84 11 | John,M,12,59,99.5 12 | Joyce,F,11,51.3,50.5 13 | Judy,F,14,64.3,90 14 | Louise,F,12,56.3,77 15 | Mary,F,15,66.5,112 16 | Philip,M,16,72,150 17 | Robert,M,12,64.8,128 18 | Ronald,M,15,67,133 19 | Thomas,M,11,57.5,85 20 | William,M,15,66.5,112 21 | -------------------------------------------------------------------------------- /tests/data/class.dlm: -------------------------------------------------------------------------------- 1 | Name Sex Age Height Weight 2 | Alfred M 14 69 112.5 3 | Alice F 13 56.5 84 4 | Barbara F 13 65.3 98 5 | Carol F 14 62.8 102.5 6 | Henry M 14 63.5 102.5 7 | James M 12 57.3 83 8 | Jane F 12 59.8 84.5 9 | Janet F 15 62.5 112.5 10 | Jeffrey M 13 62.5 84 11 | John M 12 59 99.5 12 | Joyce F 11 51.3 50.5 13 | Judy F 14 64.3 90 14 | Louise F 12 56.3 77 15 | Mary F 15 66.5 112 16 | Philip M 16 72 150 17 | Robert M 12 64.8 128 18 | Ronald M 15 67 133 19 | Thomas M 11 57.5 85 20 | William M 15 66.5 112 21 | -------------------------------------------------------------------------------- /tests/data/class.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/R-swat/847881dad284574ba3438b39db68a17b42e5d09e/tests/data/class.dta -------------------------------------------------------------------------------- /tests/data/class.jmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/R-swat/847881dad284574ba3438b39db68a17b42e5d09e/tests/data/class.jmp -------------------------------------------------------------------------------- /tests/data/class.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/R-swat/847881dad284574ba3438b39db68a17b42e5d09e/tests/data/class.rds -------------------------------------------------------------------------------- /tests/data/effort.txt: -------------------------------------------------------------------------------- 1 | country setting effort change 2 | Bolivia 46 0 1 3 | Brazil 74 0 10 4 | Chile 89 16 29 5 | Colombia 77 16 25 6 | CostaRica 84 21 29 7 | Cuba 89 15 40 8 | DominicanRep 68 14 21 9 | Ecuador 70 6 0 10 | ElSalvador 60 13 13 11 | Guatemala 55 9 4 12 | Haiti 35 3 0 13 | Honduras 51 7 7 14 | Jamaica 87 23 21 15 | Mexico 83 4 9 16 | Nicaragua 68 0 7 17 | Panama 84 19 22 18 | Paraguay 74 3 6 19 | Peru 73 0 2 20 | TrinidadTobago 84 15 29 21 | Venezuela 91 7 11 22 | -------------------------------------------------------------------------------- /tests/data/effort.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/R-swat/847881dad284574ba3438b39db68a17b42e5d09e/tests/data/effort.xlsx -------------------------------------------------------------------------------- /tests/data/effort_cas.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/R-swat/847881dad284574ba3438b39db68a17b42e5d09e/tests/data/effort_cas.xlsx -------------------------------------------------------------------------------- /tests/data/excel_test.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/R-swat/847881dad284574ba3438b39db68a17b42e5d09e/tests/data/excel_test.xlsx -------------------------------------------------------------------------------- /tests/data/missing_vals.txt: -------------------------------------------------------------------------------- 1 | n1 n2 n3 n4 l 2 | 2 5 12 NaN aa 3 | 3 6 13 16 bb 4 | 5 7 15 17 cc 5 | NaN 7 15 15 dd 6 | 5 NaN NaN 8 dd 7 | 598 120 198 1120 NA 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(swat) 3 | 4 | options(testthat.default_reporter='tap', 5 | cas.print.messages=FALSE, 6 | cas.gen.function.sig=FALSE) 7 | 8 | test_check("swat") 9 | -------------------------------------------------------------------------------- /tests/testthat/helper.data_load.R: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright SAS Institute 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the License); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | library(swat) 17 | library(testthat) 18 | 19 | options(cas.gen.function.sig=FALSE, cas.print.messages=FALSE) 20 | 21 | # 22 | # Helper package to seed data for tests 23 | # 24 | 25 | # 26 | # Setup connection parameters 27 | # 28 | 29 | # Fails in Jenkins due to older version of R not supporting withr:defer 30 | # Uncomment when running tests outside of Jenkins 31 | #withr::defer(swat::cas.terminate(caz), teardown_env()) 32 | 33 | info <- swat::.getConnectionInfo(NULL, NULL, NULL, NULL, NULL, NULL) 34 | HOSTNAME <- info$hostname 35 | PORT <- info$port 36 | USERNAME <- info$username 37 | PASSWORD <- info$password 38 | PROTOCOL <- info$protocol 39 | PATH <- '' 40 | 41 | if ( grepl('^https?:', HOSTNAME) ) { 42 | PURL <- httr::parse_url(HOSTNAME) 43 | PATH <- PURL$path 44 | HOSTNAME <- PURL$hostname 45 | } 46 | if ( HOSTNAME == '' ) { HOSTNAME = NULL } 47 | if ( PORT == '' ) { PORT <- NULL } 48 | if ( !is.null(PORT) ) { PORT <- as.numeric(PORT) } 49 | 50 | # Check for .casrc file 51 | if ( is.null(HOSTNAME) ) 52 | { 53 | casrc <- '.casrc' 54 | if ( !file.exists('.casrc') ) 55 | casrc <- file.path(path.expand('~'), '.casrc') 56 | 57 | if ( file.exists(casrc) ) 58 | { 59 | casrc <- readLines(casrc) 60 | for (i in 1:length(casrc)) 61 | { 62 | if ( grepl('^\\s*cashost\\s*=', casrc[[i]], perl=TRUE) ) 63 | HOSTNAME <- gsub('(^\\s*cashost\\s*=\\s*["\']|["\']\\s*$)', '', casrc[[i]]) 64 | else if ( grepl('^\\s*casport\\s*=', casrc[[i]], perl=TRUE) ) 65 | PORT <- as.numeric(gsub('(^\\s*casport\\s*=\\s*)', '', casrc[[i]])) 66 | else if ( grepl('^\\s*casprotocol\\s*=', casrc[[i]], perl=TRUE) ) 67 | PROTOCOL <- gsub('(^\\s*casprotocol\\s*=\\s*["\']|["\']\\s*$)', '', casrc[[i]]) 68 | } 69 | } 70 | } 71 | 72 | message(cat('NOTE: Using HOSTNAME=', HOSTNAME, ' PORT=', PORT, ' PROTOCOL=', PROTOCOL, ' PATH=', PATH, sep='')) 73 | 74 | # Create CAS connection 75 | caz <- swat::CAS(HOSTNAME, PORT, USERNAME, PASSWORD, protocol=PROTOCOL, path=PATH) 76 | 77 | # 78 | # Create test data 79 | # 80 | 81 | n1 <- c(2, 3, 5, 5, 5, 598) 82 | n2 <- c(5, 6, 7, 7, 8, 120) 83 | n3 <- c(12, 13, 15, 15, 8, 198) 84 | n4 <- c(15, 16, 17, 15, 8, 1120) 85 | n5 = c(1.2, 1.3, 1.5, 1.5, 0.8, 19.8) 86 | s <- c("aa", "bb", "cc", "dd", "dd", "dd") 87 | d <- c('12/31/09', '09/08/78', '12/25/00','04/01/16', '06/17/80', '03/08/02') 88 | d <- as.Date(d, "%m/%d/%y") 89 | df <- data.frame(n1, n2, n3, n4, s, d) 90 | df_ <- data.frame(n1, n2, n3, n4, n5, s, d) 91 | 92 | # Create data frame with missing values and invalid SAS column names 93 | n1.1 <- c(2, 3, 5, NA, 5, 598) 94 | n2.1 <- c(5, 6, 7, 7, NA, 120) 95 | n3.1 <- c(12, 13, 15, 15, 13, 198) 96 | n4.1 <- c(NA, 16, 17, 15, 8, 1120) 97 | n5.1 = c(1.2, 1.3, 1.5, 1.5, 0.8, NA) 98 | s.1 <- c("aa", "bb", "cc", "dd", "dd", "dd") 99 | s0.1 <- c("aa", "bb", "cc", "dd", "dd", " ") 100 | d.1 <- c('12/31/09', '09/08/78', '12/25/00','04/01/16', NA, '03/08/02') 101 | d.1 <- as.Date(d, "%m/%d/%y") 102 | df0.1 <- data.frame(n1.1, n2.1, n3.1, n4.1, s.1, d.1) 103 | df0_.1 <- data.frame(n1.1, n2.1, n3.1, n4.1, s0.1, d.1) 104 | 105 | # Create data frame with missing values 106 | n1 <- c(2, 3, 5, NA, 5, 598) 107 | n2 <- c(5, 6, 7, 7, NA, 120) 108 | n3 <- c(12, 13, 15, 15, 13, 198) 109 | n4 <- c(NA, 16, 17, 15, 8, 1120) 110 | n5 = c(1.2, 1.3, 1.5, 1.5, 0.8, NA) 111 | s <- c("aa", "bb", "cc", "dd", "dd", "dd") 112 | s0 <- c("aa", "bb", "cc", "dd", "dd", " ") 113 | d <- c('12/31/09', '09/08/78', '12/25/00','04/01/16', NA, '03/08/02') 114 | d <- as.Date(d, "%m/%d/%y") 115 | df0 <- data.frame(n1, n2, n3, n4, s, d) 116 | df0_ <- data.frame(n1, n2, n3, n4, n5, s0, d) 117 | 118 | # data.frame with only numeric data 119 | dfn <- data.frame(n1, n2, n3, n4) 120 | 121 | df1 <- data.frame(matrix(rnorm(20), 10)) 122 | df2 <- data.frame(matrix(rnorm(20), 10)) 123 | df3 <- data.frame(matrix(rnorm(20), 10)) 124 | names(df3) <- c("V3", "V4") 125 | 126 | # Load data to CAS 127 | ct1 <- as.casTable(caz, df1, casOut=list(replace=TRUE)) 128 | ct2 <- as.casTable(caz, df2, casOut=list(replace=TRUE)) 129 | ct3 <- as.casTable(caz, df3, casOut=list(replace=TRUE)) 130 | 131 | ct0.1 <- as.casTable(caz, df0.1, casOut=list(replace=TRUE)) 132 | ct0 <- as.casTable(caz, df0, casOut=list(replace=TRUE)) 133 | ct <- as.casTable(caz, df, casOut=list(replace=TRUE)) 134 | i2 <- as.casTable(caz, iris, casOut=list(replace=TRUE)) 135 | df.ct <- as.casTable(caz, df_, casOut=list(replace=TRUE)) 136 | df0.ct <- as.casTable(caz, df0_, casOut=list(replace=TRUE)) 137 | df0_1.ct <- as.casTable(caz, df0_.1, casOut=list(replace=TRUE)) 138 | 139 | ctn <- as.casTable(caz, dfn, casOut=list(replace=TRUE)) 140 | 141 | ct_cmp <- as.casTable(caz, df, casOut = list(name='ct_cmp', replace=TRUE)) 142 | ct_cmp["cv1"] <- ct_cmp$n1 + 0 143 | ct_cmp["cv2"] <- ct_cmp$n2 + 0 144 | ct_cmp["cv3"] <- ct_cmp$n3 + 0 145 | df_cmp <- to.data.frame(to.casDataFrame(ct_cmp)) 146 | 147 | 148 | 149 | titanic <- read.csv('http://s3.amazonaws.com/assets.datacamp.com/course/Kaggle/train.csv') 150 | t <- as.casTable(caz, titanic, casOut=list(replace=TRUE)) 151 | 152 | titanic.csv <- tempfile(pattern='titanic_', fileext='.csv') 153 | write.csv(titanic, file = titanic.csv) 154 | mtcars.ct = as.casTable(caz, mtcars, casOut=list(replace=TRUE)) 155 | -------------------------------------------------------------------------------- /tests/testthat/test.analysis_compvars.R: -------------------------------------------------------------------------------- 1 | # test.analysis_compvars.R 2 | 3 | library(swat) 4 | 5 | options(cas.print.messages=FALSE) 6 | 7 | 8 | context("test.analysis_compvars.R") 9 | test_that("unique", { 10 | # Computed columns are not supported with the unique function 11 | expect_error(expect_equivalent(unique(ct_cmp$n1), unique(ct_cmp$cv1))) 12 | expect_error(expect_equivalent(unique(ct_cmp$cv1), unique(df_cmp$cv1))) 13 | expect_error(expect_equivalent(unique(ct_cmp[c(1:3,6:8)]), unique(df_cmp[c(1:3,6:8)]))) 14 | }) 15 | 16 | test_that("subset", { 17 | expect_equivalent(subset(ct_cmp, subset = ct_cmp$cv1 > 15, select = c("n1", "n2", "cv1"), drop = FALSE), 18 | as.casTable(caz, subset(df_cmp, subset = df_cmp$cv2 > 15, select = c("n1", "n2", "cv1"), drop = FALSE), 19 | casOut =list(name='foobar', replace=TRUE))) 20 | }) 21 | 22 | test_that("nrow", { 23 | expect_equivalent(6, nrow(ct_cmp)) 24 | expect_equivalent(6, nrow(ct_cmp[6:8])) 25 | }) 26 | 27 | test_that("ncol", { 28 | expect_equivalent(4, ncol(ct_cmp[5:8])) 29 | expect_equivalent(1, ncol(ct_cmp[7])) 30 | expect_equivalent(1, ncol(ct_cmp$cv1)) 31 | }) 32 | 33 | test_that("dim", { 34 | expect_equivalent(dim(df_cmp[1]), dim(ct_cmp[1])) 35 | expect_equivalent(dim(df_cmp[4:8]), dim(ct_cmp[4:8])) 36 | expect_equivalent(dim(cas.count(ct_cmp[4:8])), c(3,2)) 37 | }) 38 | 39 | # test_that("min, max, median", { 40 | # min(df_cmp[8]) 41 | # bench <-c(8, 8, 2, 5 ) 42 | # expect_equivalent(cas.min(ct_cmp[3:8])[2], as.data.frame(bench)) 43 | # 44 | # expect_true(all.equal(cas.min(ct_cmp[3:8][2]), 45 | # as.data.frame(sapply(df_cmp[c(3:4, 7:8)], min, na.rm = TRUE)), check.attributes=FALSE )) 46 | # 47 | # expect_true(all.equal(cas.max(ct_cmp[3:8][2]), 48 | # as.data.frame(sapply(df_cmp[c(3:4, 7:8)], max, na.rm = TRUE)), check.attributes=FALSE )) 49 | # 50 | # expect_true(all.equal(cas.median(ct_cmp[3:8][2]), 51 | # as.data.frame(sapply(df_cmp[c(3:4, 7:8)], median, na.rm = TRUE)), check.attributes=FALSE )) 52 | # }) 53 | 54 | test_that("min, max, median", { 55 | min(df_cmp[8]) 56 | bench <-c(8, 8, 2, 5 ) 57 | expect_equivalent(cas.min(ct_cmp[3:8])[2], as.data.frame(bench)) 58 | 59 | expect_equivalent(cas.min(ct_cmp[3:8])[2], 60 | as.data.frame(sapply(df_cmp[c(3:4, 7:8)], min, na.rm = TRUE)) ) 61 | 62 | expect_equivalent(cas.max(ct_cmp[3:8])[2], 63 | as.data.frame(sapply(df_cmp[c(3:4, 7:8)], max, na.rm = TRUE)) ) 64 | 65 | expect_equivalent(cas.median(ct_cmp[3:8])[2], 66 | as.data.frame(sapply(df_cmp[c(3:4, 7:8)], median, na.rm = TRUE)) ) 67 | }) 68 | 69 | test_that("mode", { 70 | bench <- c(3,2,2,2,3,1,3,2) 71 | expect_true(all.equal(cas.mode(ct_cmp[1:8])[3], 72 | as.data.frame(bench), check.attributes=FALSE )) 73 | }) 74 | 75 | test_that("tvalue", { 76 | expect_equivalent(cas.tvalue(ct_cmp[1:2]), cas.tvalue(ct_cmp[7:8])) 77 | expect_equivalent(length(cas.tvalue(ct_cmp[3:8])), 4) 78 | }) 79 | 80 | test_that("colSums", { 81 | expect_equivalent(colSums(df_cmp[c(1:4,7:8)]), colSums(ct_cmp[c(1:4,7:8)])) 82 | }) 83 | 84 | test_that("head, tail", { 85 | expect_equivalent(head(df_cmp[c(1:4,7:8)], 4), head(ct_cmp[c(1:4,7:8)], 4)) 86 | 87 | 88 | expect_equivalent(tail(df_cmp[c(1:4,7:8)], 4), tail(ct_cmp[c(1:4,7:8)], 4)) 89 | }) 90 | 91 | test_that("cor, cov", { 92 | expect_equal(cor(df_cmp[c(1:4,7:8)], use = "complete"), cor(ct_cmp[c(1:4,7:8)], use = "complete"), tolerance = 1.e-5) 93 | 94 | expect_equivalent(cov(ct_cmp$n1, ct_cmp$n2), cov(df_cmp$cv1, df_cmp$cv2)) 95 | expect_equivalent(cov(ct_cmp$n1, ct_cmp$n2), cov(ct_cmp$cv1, ct_cmp$cv2)) 96 | expect_true(all.equal(cov(df_cmp[c(1:4,7:8)]), cov(ct_cmp[c(1:4,7:8)]), tolerance = 1.e-6)) 97 | }) 98 | 99 | test_that("summary", { 100 | skip("fails in Jenkins") 101 | # summary(df_cmp) is incorrect in several places when run in Jenkins with R3.5 ( 3.6+ is ok ) 102 | expect_true(all.equal(summary(ct_cmp[c(1:4,7:8)]), summary(df_cmp[c(1:4,7:8)], quantile.type = 2), check.attributes = FALSE)) 103 | }) 104 | -------------------------------------------------------------------------------- /tests/testthat/test.datetime.R: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright SAS Institute 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the License); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | library(swat) 17 | 18 | options(cas.print.messages=FALSE) 19 | 20 | 21 | context('test.datetime.R') 22 | 23 | test_that('test.cas.datetime', { 24 | expect_equal(class(cas2rPOSIXct('315662400000000')), c('POSIXct', 'POSIXt')) 25 | expect_equal(cas2rPOSIXct('315662400000000'), 26 | as.POSIXct(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 27 | expect_equal(cas2rPOSIXct(315662400000000), 28 | as.POSIXct(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 29 | 30 | expect_equal(class(cas2rPOSIXlt('315662400000000')), c('POSIXlt', 'POSIXt')) 31 | expect_equal(cas2rPOSIXlt('315662400000000'), 32 | as.POSIXlt(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 33 | expect_equal(cas2rPOSIXlt(315662400000000), 34 | as.POSIXlt(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 35 | 36 | expect_equal(cas2sasDateTime('315662400000000'), 315662400) 37 | expect_equal(cas2sasDateTime(315662400000000), 315662400) 38 | 39 | expect_equal(class(cas2rDate(3653)), 'Date') 40 | expect_equal(cas2rDate(3653), 41 | as.Date(as.POSIXlt(origin='1970-01-01', tz='UTC', 0))) 42 | expect_equal(cas2sasDate(3653), 3653) 43 | 44 | expect_equal(class(casTime2rPOSIXct('43200000000')), c('POSIXct', 'POSIXt')) 45 | expect_equal(casTime2rPOSIXct('43200000000'), 46 | as.POSIXct(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 47 | expect_equal(casTime2rPOSIXct(43200000000), 48 | as.POSIXct(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 49 | 50 | expect_equal(class(casTime2rPOSIXlt('43200000000')), c('POSIXlt', 'POSIXt')) 51 | expect_equal(casTime2rPOSIXlt('43200000000'), 52 | as.POSIXct(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 53 | expect_equal(casTime2rPOSIXlt(43200000000), 54 | as.POSIXlt(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 55 | 56 | expect_equal(cas2sasTime('43200000000'), 43200) 57 | expect_equal(cas2sasTime(43200000000), 43200) 58 | }) 59 | 60 | test_that('test.r2cas', { 61 | expect_equal(rPOSIXlt2cas(as.POSIXlt(strptime("1970-01-01 12:00:00", 62 | "%Y-%m-%d %H:%M:%S", tz='UTC'))), 63 | 315662400000000) 64 | expect_equal(rPOSIXct2cas(as.POSIXct(strptime("1970-01-01 12:00:00", 65 | "%Y-%m-%d %H:%M:%S", tz='UTC'))), 66 | 315662400000000) 67 | 68 | expect_equal(rDate2cas(as.Date(as.POSIXlt(origin='1970-01-01', tz='UTC', 0))), 3653) 69 | }) 70 | 71 | test_that('test.sas.datetime', { 72 | expect_equal(class(sas2rPOSIXct('315662400')), c('POSIXct', 'POSIXt')) 73 | expect_equal(sas2rPOSIXct('315662400'), 74 | as.POSIXct(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 75 | expect_equal(sas2rPOSIXct(315662400), 76 | as.POSIXct(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 77 | 78 | expect_equal(class(sas2rPOSIXlt('315662400')), c('POSIXlt', 'POSIXt')) 79 | expect_equal(sas2rPOSIXlt('315662400'), 80 | as.POSIXlt(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 81 | expect_equal(sas2rPOSIXlt(315662400), 82 | as.POSIXlt(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 83 | 84 | expect_equal(sas2casDateTime('315662400'), 315662400000000) 85 | expect_equal(sas2casDateTime(315662400), 315662400000000) 86 | 87 | expect_equal(class(sas2rDate(3653)), 'Date') 88 | expect_equal(sas2rDate(3653), 89 | as.Date(as.POSIXlt(origin='1970-01-01', tz='UTC', 0))) 90 | expect_equal(sas2casDate(3653), 3653) 91 | 92 | expect_equal(class(sasTime2rPOSIXct('43200')), c('POSIXct', 'POSIXt')) 93 | expect_equal(sasTime2rPOSIXct('43200'), 94 | as.POSIXct(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 95 | expect_equal(sasTime2rPOSIXct(43200), 96 | as.POSIXct(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 97 | 98 | expect_equal(class(sasTime2rPOSIXlt('43200')), c('POSIXlt', 'POSIXt')) 99 | expect_equal(sasTime2rPOSIXlt('43200'), 100 | as.POSIXlt(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 101 | expect_equal(sasTime2rPOSIXlt(43200), 102 | as.POSIXlt(strptime("1970-01-01 12:00:00", "%Y-%m-%d %H:%M:%S", tz='UTC'))) 103 | 104 | expect_equal(sas2casTime('43200'), 43200000000) 105 | expect_equal(sas2casTime(43200), 43200000000) 106 | }) 107 | 108 | test_that('test.r2sas', { 109 | expect_equal(rPOSIXlt2sas(as.POSIXlt(strptime("1970-01-01 12:00:00", 110 | "%Y-%m-%d %H:%M:%S", tz='UTC'))), 111 | 315662400) 112 | expect_equal(rPOSIXct2sas(as.POSIXct(strptime("1970-01-01 12:00:00", 113 | "%Y-%m-%d %H:%M:%S", tz='UTC'))), 114 | 315662400) 115 | 116 | expect_equal(rDate2sas(as.Date(as.POSIXlt(origin='1970-01-01', tz='UTC', 0))), 3653) 117 | }) 118 | -------------------------------------------------------------------------------- /tests/testthat/test.general_functions.R: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright SAS Institute 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the License); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | library(swat) 17 | 18 | options(cas.print.messages=FALSE) 19 | 20 | 21 | context("general_functions") 22 | 23 | test_that("Load ActionSet and List ActionSet Functions", { 24 | expect_error(swat::loadActionSet(caz, "foobar")) 25 | expect_null(swat::loadActionSet(caz, "builtins")) 26 | 27 | loadActionSet(caz, actionSet="simple") 28 | expect_true("simple" %in% listActionSets(caz)$actionset) 29 | 30 | p <- listActionParms(caz, actn="summary", display=FALSE) 31 | expect_true(length(p) > 15) 32 | expect_equivalent(p[[1]]$name, 'table') 33 | expect_equivalent(p[[1]]$parmType, 'value_list') 34 | }) 35 | 36 | 37 | test_that("Test that the class for R-SWAT objects is returned correctly", { 38 | expect_is(caz, "CAS") 39 | expect_is(ct, "CASTable") 40 | expect_is(to.casDataFrame(ct), "casDataFrame") 41 | }) 42 | -------------------------------------------------------------------------------- /tests/testthat/test.graphics.R: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright SAS Institute 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the License); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | 17 | library(swat) 18 | 19 | options(cas.print.messages=FALSE) 20 | 21 | 22 | context("test.graphics.R") 23 | 24 | verify_jpeg_pkg <- function () { 25 | tryCatch({ 26 | library(jpeg) 27 | dfplot <- tempfile(fileext='.jpg') 28 | tryCatch({ 29 | jpeg(dfplot) 30 | plot(iris$Sepal.Length, iris$Sepal.Width) 31 | dev.off() 32 | unlink(dfplot) 33 | }, error = function (e) { 34 | testthat::skip('"jpeg" library is not functional.') 35 | unlink(dfplot) 36 | }) 37 | }, error = function (e) { 38 | testthat::skip('"jpeg" library is not installed to compare JPEG files.') 39 | unlink(dfplot) 40 | }) 41 | } 42 | 43 | test_that("plot.scatter", { 44 | verify_jpeg_pkg() 45 | 46 | dfplot <- tempfile(fileext='.jpg') 47 | jpeg(dfplot) 48 | plot(iris$Sepal.Length, iris$Sepal.Width, xlab='Sepal Length', ylab='Sepal Width') 49 | dev.off() 50 | 51 | casplot <- tempfile(fileext='.jpg') 52 | jpeg(casplot) 53 | plot(i2$Sepal.Length, i2$Sepal.Width, xlab='Sepal Length', ylab='Sepal Width') 54 | dev.off() 55 | 56 | expect_equal(readJPEG(dfplot), readJPEG(casplot), tolerance=0.018) 57 | 58 | unlink(dfplot) 59 | unlink(casplot) 60 | }) 61 | 62 | test_that('plot.bar', { 63 | verify_jpeg_pkg() 64 | 65 | dfplot <- tempfile(fileext='.jpg') 66 | jpeg(dfplot) 67 | plot(iris$Sepal.Length, iris$Sepal.Width, xlab='Sepal Length', ylab='Sepal Width', type='h', col='red', lwd=10) 68 | dev.off() 69 | 70 | casplot <- tempfile(fileext='.jpg') 71 | jpeg(casplot) 72 | plot(i2$Sepal.Length, i2$Sepal.Width, xlab='Sepal Length', ylab='Sepal Width', type='h', col='red', lwd=10) 73 | dev.off() 74 | 75 | expect_equal(readJPEG(dfplot), readJPEG(casplot), tolerance=0.018) 76 | 77 | unlink(dfplot) 78 | unlink(casplot) 79 | }) 80 | -------------------------------------------------------------------------------- /tests/testthat/test.helper.R: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright SAS Institute 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the License); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | library(swat) 17 | library(testthat) 18 | 19 | options(cas.print.messages=FALSE) 20 | 21 | 22 | context("test.helper.R") 23 | 24 | test_that("casFormula Functions", { 25 | t1 <- y ~ x1 26 | casFormula(t1) 27 | expect_that(casFormula(t1), is_a("list")) 28 | 29 | t2 <- y ~ x1 + x2 30 | expect_that(casFormula(t2), is_a("list")) 31 | 32 | t3 <- y ~ x1 + x2 + x3 33 | foo <- casFormula(t3) 34 | valid <- list(as.name('y'),c('x1','x2','x3')) 35 | expect_equivalent(foo[[1]], as.name('y')) 36 | expect_equivalent(foo, valid) 37 | 38 | 39 | t4 <- y ~ x1 + x2 * x3 40 | expect_error(casFormula(t4)) 41 | 42 | t5 <- ~ x1 + x2 * x3 43 | expect_error(casFormula(t5)) 44 | }) 45 | 46 | test_that("help function",{ 47 | #expect_message(help(cas.aStore.describe),regexp = "Using") 48 | #expect_message(help(cas.network.readGraph),regexp = "Using") 49 | expect_silent(help(cas.foo.bar)) 50 | }) 51 | -------------------------------------------------------------------------------- /tests/testthat/test.operator_indexing.R: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright SAS Institute 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the License); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | library(swat) 17 | 18 | options(cas.print.messages=FALSE) 19 | 20 | 21 | context("test.operatorindexing.R") 22 | 23 | test_that("test that multi-column referencing with : works", { 24 | 25 | expect_equivalent(colSums(ct[1:4]), colSums(df[1:4])) 26 | expect_equivalent(median(ct[2]), median(data.matrix(df[2]))) 27 | # 28 | # swat::median returns the median for each column. stats::median.default returns 29 | # the median across all selected columns, it seems. 30 | # 31 | expect_failure(expect_equivalent(median(ct[2:3]), median(data.matrix(df[2:3])))) 32 | }) 33 | 34 | test_that("test that multi-comlumn referencing with vector works", { 35 | 36 | expect_equivalent(colMeans(ct[c(1, 3, 4)]), colMeans(df[c(1, 3, 4)])) 37 | expect_equivalent(colSums(ct[c(2, 3)]), colSums(df[c(2, 3)])) 38 | }) 39 | 40 | test_that("test that referencing with $ operator works", { 41 | 42 | expect_equivalent(colSums(ct$n3), colSums(data.matrix(df$n3))) 43 | }) 44 | 45 | test_that("test that referencing with column names works", { 46 | 47 | ct13 <- ct[c('n1' , 'n3')] 48 | expect_equivalent(ct[c('n1' , 'n3')], ct13) 49 | 50 | colSums(ct13) 51 | colMeans(ct13) 52 | 53 | colSums(ct13[1]) 54 | colMeans(ct13[2]) 55 | 56 | expect_equivalent(max(ct[[1]]), max(df[[1]])) 57 | expect_equivalent(max(ct[['n4']]), max(df[['n4']])) 58 | }) 59 | 60 | # Row indexing is not currenly supported 61 | -------------------------------------------------------------------------------- /tests/testthat/test.rbind.R: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright SAS Institute 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the License); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | library(swat) 17 | 18 | options(cas.print.messages=FALSE) 19 | 20 | 21 | context("test.rbind.R") 22 | 23 | test_that("test that rbind basic functionality works", { 24 | 25 | expect_is(ct1, "CASTable") 26 | expect_is(ct2, "CASTable") 27 | 28 | expect_that(rbind(ct1, ct2), is_a("CASTable")) 29 | }) 30 | 31 | test_that("test that rbind work for R data frames.", { 32 | 33 | expect_is(df1, "data.frame") 34 | expect_is(df2, "data.frame") 35 | 36 | expect_that(rbind(df1, df2), is_a("data.frame")) 37 | 38 | expect_is(ct1, "CASTable") 39 | expect_is(ct2, "CASTable") 40 | 41 | expect_equivalent(colSums(rbind(ct1,ct2)), colSums(rbind(df1,df2))) 42 | expect_error(rbind(df1,ct2)) 43 | 44 | }) 45 | 46 | test_that("test that rbind works with assignment", { 47 | 48 | nct <-rbind(ct1, ct2) 49 | expect_that(nct, is_a("CASTable")) 50 | expect_equivalent(rbind(ct1, ct2), nct) 51 | }) 52 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | # 2 | # Tox configuration for testing Anaconda and pip Python SWAT packages. 3 | # 4 | 5 | [flake8] 6 | ignore = F401,W503 7 | max-line-length = 90 8 | max-complexity = 80 9 | inline-quotes = single 10 | multiline-quotes = single 11 | 12 | [tox] 13 | requires = tox-conda 14 | envlist = {r,mro}-{base} 15 | toxworkdir = {env:TOX_WORK_DIR:{toxinidir}/.tox} 16 | skipsdist = True 17 | whitelist_externals = 18 | /bin/rm 19 | 20 | [testenv] 21 | basepython = python3.6 22 | setenv = 23 | PATH = {envbindir}:/usr/bin:/bin 24 | passenv = 25 | CASURL 26 | CAS_URL 27 | CASHOST 28 | CAS_HOST 29 | CASPORT 30 | CAS_PORT 31 | CASPROTOCOL 32 | CAS_PROTOCOL 33 | CASUSER 34 | CAS_USER 35 | CASPASSWORD 36 | CAS_PASSWORD 37 | CASTOKEN 38 | CAS_TOKEN 39 | CONDA_PKGS_DIRS 40 | CONDA_CHANNEL_URL 41 | CONDA_SUBDIR 42 | PYPI_URL 43 | NOSETESTS_ARGS 44 | SWAT_VERSION_EXPR 45 | WINDIR 46 | conda_deps = 47 | conda 48 | r-httr 49 | r-jsonlite 50 | r-testthat 51 | 52 | # cd to anything but the default {toxinidir}. 53 | changedir = {envdir} 54 | 55 | 56 | [testenv:conda] 57 | commands = 58 | - /bin/rm -rf {env:CONDA_PKGS_DIRS:/tmp}/r-swat-* 59 | - {envbindir}/conda uninstall -y -q r-swat 60 | {envbindir}/conda install -y -q -c {env:CONDA_CHANNEL_URL:conda} -c sas-institute r-swat{env:SWAT_VERSION_EXPR:} 61 | {envbindir}/conda list --show-channel-urls r-swat 62 | {envbindir}/R -e "testthat::test_package('swat', stop_on_failure=TRUE)" 63 | - {envbindir}/conda uninstall -y -q r-swat 64 | - /bin/rm -rf {env:CONDA_PKGS_DIRS:/tmp}/r-swat-* 65 | 66 | 67 | [testenv:r-base] 68 | commands = {[testenv:conda]commands} 69 | conda_deps = 70 | r-base 71 | {[testenv]conda_deps} 72 | 73 | [testenv:mro-base] 74 | commands = {[testenv:conda]commands} 75 | conda_deps = 76 | mro-base 77 | {[testenv]conda_deps} 78 | --------------------------------------------------------------------------------