11:02, 12th May 2021
6 Life-Altering RStudio Keyboard Shortcuts
Written by Matt Dancho of Business Science, this article highlights six keyboard shortcuts in the RStudio integrated development environment that are designed to boost productivity for R programmers. The shortcuts covered include commenting and uncommenting code, inserting the pipe operator, adding the assignment operator, selecting multiple lines with a multi-cursor tool, searching for specific terms across files and accessing a full keyboard shortcut reference sheet. Each shortcut is presented as a practical time-saver for common coding tasks, particularly those involving data wrangling and function building.
11:01, 12th May 2021
Rtools
Rtools is a collection of compilers, build utilities and Unix-like tools designed to enable the compilation of R packages on Windows, which lacks these components by default. It includes the GCC toolchain for C, C++ and Fortran, along with utilities such as make, tar and bash that replicate the Linux build environment commonly assumed by R packages. Rtools is essential for installing packages containing compiled code from source, installing development versions from repositories like GitHub, or creating custom packages with C/C++ extensions. Each R version requires a corresponding Rtools version to ensure compatibility, and proper installation involves adding it to the system PATH to allow seamless compilation during package installation. On Windows, Rtools serves as the equivalent of the standard build tools found on Linux and macOS, enabling the automatic construction of packages with compiled components without requiring users to manually manage the underlying infrastructure.
10:53, 12th May 2021
SAS Free Software Trials
SAS offers free trials and resources tailored to different user groups, including organisations seeking to test its data and AI platform, students and educators accessing software and training materials and professionals exploring learning subscriptions or career-specific courses. These initiatives aim to support skill development, academic instruction and organisational innovation through access to analytics tools, visualisation capabilities and industry-focused solutions. Additional options are available for purchasing licences and tailored industry applications, covering areas such as data management, decisioning and advanced analytics.
10:52, 12th May 2021
Open Integration with SAS
SAS Viya facilitates collaboration between SAS users and open-source developers by integrating open-source technology throughout the analytics process, enabling models to be deployed across various environments such as cloud platforms, private docker containers and through APIs. This approach supports governance and orchestration of analytics workflows, allowing models developed in multiple languages to be managed centrally and scaled effectively.
By leveraging REST and language-specific APIs, organisations can embed analytics into business applications, enhancing decision-making and operational efficiency. Examples from various industries demonstrate how this integration helps organisations streamline complex analytics ecosystems, foster innovation and make data-driven decisions at different levels of an organisation, with support for multiple programming languages and deployment options.
10:50, 12th May 2021
SAS Developer Home
The SAS Developer Portal is a resource for building applications that integrate SAS artificial intelligence and analytics capabilities with open-source technologies, offering a range of REST APIs spanning areas such as machine learning, data management, fraud detection, generative AI, health and life sciences, IoT analytics and visualisation. Developers can explore use cases drawn from various SAS media outlets, access libraries for integration with Python, R, Lua and Java, and learn how to run SAS code on the SAS Viya platform using CAS actions or the SAS extension for Visual Studio Code.
Software development kits are also available for embedding insights and content from SAS Viya into custom dashboards and applications, while featured solutions include Customer Intelligence 360, SAS Viya Workbench and a Trustworthy AI platform centred on transparency and accountability. A developer community and GitHub repositories provide further opportunities for collaboration, knowledge sharing and access to code examples and tools, with an annual conference bringing together leaders, users and partners to advance their knowledge of the platform.
10:48, 12th May 2021
How to Check if a File or a Directory exists in R, Python and Bash
When building data workflows and machine learning pipelines, it is often necessary to verify whether specific files or directories exist before proceeding. In R, this can be done using the base package commands file.exists() and dir.exists(), with new files and directories created using file.create() and dir.create() respectively. Python offers two main approaches through the os and pathlib modules, where os.path.isfile(), os.path.isdir() and os.path.exists() handle these checks, while new files and directories can be created using open() and os.makedirs(). In Bash, the same checks are performed using flags within conditional statements, with -f used for files and -d for directories, and new files and directories created with the touch and mkdir commands respectively, alongside a range of additional flags available for more specific checks such as verifying file permissions, ownership and type.
10:46, 12th May 2021
Deleting a substring from a SAS string
Leonid Batkhan's SAS Users blog post explains how to delete substrings from SAS character variables and macro variables, framing this as the reverse of a previously covered substring insertion technique. For removing all instances of an unwanted substring from a character variable, the post demonstrates use of the TRANSTRN function paired with TRIMN, which together allow a zero-length replacement that effectively erases the target string. When working with macro variables, two approaches are presented, one using a data step with TRANSTRN and CALL SYMPUTX, and another using %SYSFUNC within the macro language.
For cases where only a specific occurrence of a substring needs to be removed rather than all of them, the post outlines two further solutions, one using SUBSTR and CATX to cut and rejoin the string around the unwanted portion, and another using the KUPDATE function for a more concise result. The FIND function is used to locate the precise position of the target substring, with its direction argument allowing searches from right to left. The post also notes that FINDNTH can be used when the goal is to remove a particular numbered instance of a repeated substring.
10:45, 12th May 2021
10 Tips And Tricks For Data Scientists Vol.6
This sixth instalment in a series of data science tips covers a range of practical techniques in both Python and R. In Python, the tips include finding the mode of a list using the max function with a lambda key, disabling warnings via the warnings module, pasting copied data directly into a Pandas DataFrame using read_clipboard, saving DataFrames as image files with the dataframe-image library and tracking the progress of applied functions using the tqdm library.
On the R side, the article advises using the matrixStats package over the apply function for large datasets, recommending the data.table package for reading and writing CSV files due to its significantly faster performance compared to base R and the readr package. It also introduces the waldo package for comparing R objects and identifying differences in a clear, colour-coded format, demonstrates how to dynamically check for and install required packages before loading them and shows how to convert all character variables to factors in a single line of code using sapply and lapply.
10:42, 12th May 2021
Time series analysis in R covers several key areas, including decomposition, forecasting, clustering and classification. Using the AirPassengers dataset, which spans 1949 to 1961 across 144 observations, the data can be log-transformed to address non-stationarity before being decomposed into trend, seasonal and random components, with notable seasonal peaks in months seven and eight and a trough in month eleven.
For forecasting, an ARIMA model is fitted using automatic selection, with ACF and PACF plots used to assess residuals, and a Ljung-Box test confirming that any apparent autocorrelation is likely due to chance rather than a model deficiency. The resulting forecast achieves strong accuracy, with residuals closely approximating a normal distribution centred at zero.
For clustering, dynamic time warping is used to calculate distances between series exhibiting six distinct patterns, including normal, cyclic, increasing trend, decreasing trend, upward shift and downward shift, before hierarchical clustering groups them accordingly. Finally, a decision tree classifier trained on the same patterned data achieves an overall accuracy of above 95%, demonstrating that time series patterns can be reliably identified and categorised using R.
10:42, 12th May 2021
Code performance in R: Which part of the code is slow?
Code performance in R: How to make code faster
Improving the performance of R code requires a combination of smart coding habits and the right diagnostic tools. Profiling tools such as the system.time function and the microbenchmark and profvis packages allow developers to identify which parts of their code are slowest, enabling targeted optimisation rather than guesswork. Once bottlenecks are identified, several techniques can meaningfully reduce computation time, including avoiding redundant operations within loops by moving static calculations outside them, pre-allocating vectors of the required length rather than appending values incrementally and collapsing strings in a single step rather than building them piece by piece.
Vectorisation offers particularly significant speed gains by leveraging internally compiled C-based loops, and functions such as rowSums, rowMeans, colSums and colMeans provide ready-made vectorised alternatives to manual iteration. Where vectorisation is not possible, translating performance-critical code into C++ using the Rcpp package can achieve comparable results. Saving intermediate results to file also reduces unnecessary recomputation across longer workflows.