Technology Tales

Notes drawn from experiences in consumer and enterprise technology

08:58, 26th November 2021

A fresh start for R in VSCode

Visual Studio Code (VSCode) can be configured as a fully functional development environment for R programming through the installation of a few key components. The process involves installing the languageserver package within the R console, followed by two VSCode extensions, namely the R Extension by Yuki Ueda and the R LSP Client by REditorSupport, which together provide features such as shortcuts, environment viewing, linting, autocomplete and intelligent function suggestions. A Python module called Radian serves as a modern alternative to the standard R console, offering improved colour schemes and output representations. Once these components are in place, a handful of configuration lines added to the editor's settings file are sufficient to complete the setup, resulting in a lightweight yet capable environment that rivals a dedicated R IDE.

08:57, 26th November 2021

R and radian on macOS and VSCode

Setting up R with VSCode on macOS requires several components to work together correctly. R itself must be installed from the official CRAN repository alongside XQuartz, while radian, a popular alternative R console, can be installed via its GitHub repository.

A common issue on macOS is a runtime error related to a missing R home directory, which can be resolved by locating the correct path within the R application and exporting it as an environment variable, then saving that setting permanently in a shell configuration file. The R extension for VSCode, developed by Yuki Ueda, enables running R code directly from the editor, though it requires radian to be correctly configured within the extension settings along with bracketed paste being enabled.

Additional configuration, such as setting the correct R executable path, allows the help topic viewer and function helper to work properly within the editor. For those wanting linting and autocompletion support, the R LSP Client extension by REditorSupport can be installed alongside the corresponding language server from CRAN.

08:57, 26th November 2021

Writing R in VSCode: Interacting with an R session

Using R interactively within VSCode is made possible through the R session watcher feature found in the vscode-R extension, which allows the editor to communicate with a live R session across a range of scenarios. For a smoother experience, using radian as the default R console is recommended, as it offers syntax highlighting, auto-completion and improved handling of code chunks and unicode characters.

When connecting to a remote server via SSH and managing R sessions within a tmux window, several configuration options help ensure that code is always sent to the active terminal and that sessions persist beyond the editor closing. Multiple R sessions can be run simultaneously across different tmux windows and safely restored when needed.

Document formatting based on styler is available but can be slow for larger scripts, so disabling automatic formatting on save and running it manually on demand is a practical alternative. The overall setup supports a wide range of interactive R features, including viewing data frames, global environments, functions, vectors and objects, as well as displaying plots, htmlwidgets, Shiny applications and code profiling results, alongside session symbol completion and help documentation.

16:12, 18th November 2021

SAS Viya REST APIs

The SAS Viya REST API platform is a comprehensive suite of developer tools designed to allow enterprise application developers to build upon the work of data scientists and model builders using any client technology. The platform covers a broad range of functional areas, including data management, model building and publishing, job execution, authorisation, machine learning automation, event stream processing, fraud compliance and clinical data management. Individual APIs handle specific tasks such as managing files and folders, defining and executing scoring and decision logic, retrieving and querying data, managing user identities and running business rules. More specialist capabilities include real-time watch list screening for financial crime detection, clinical job management, retrieval agent querying for conversational responses and workflow execution based on the BPMN 2.0 standard. Supporting resources include a developer community forum and code examples hosted on GitHub, and the full list of APIs can be browsed alphabetically or filtered by category.

08:13, 18th November 2021

{fusen} is now available on CRAN!

The fusen R package, developed by ThinkR, is now available on CRAN and offers R users a streamlined way to build fully documented and tested packages from a single R Markdown file. Rather than writing code, examples and tests across multiple separate directories, developers can consolidate everything into one file and use a single inflate command to generate a complete package structure. The package is intended to lower the barrier to entry for those who have never built an R package before, while also benefiting experienced developers who want a more efficient workflow. It is particularly suited to data analysts who already use R Markdown for reproducibility and want to formalise their work into a robust, shareable package. By combining {fusen} with version control tools such as Git, users can keep track of changes and make their work easier for colleagues to understand, adapt and reproduce.

14:53, 17th November 2021

Python Try Except

Python's try/except mechanism provides a structured way to handle runtime errors, preventing programmes from crashing unexpectedly. The try block contains code that is tested for errors, while the except block defines how those errors are handled, with the option to specify multiple except blocks for different error types. An else block can be included to run code only when no errors occur, and a finally block executes regardless of whether an error was raised, making it useful for closing files or freeing up resources. Developers can also manually trigger errors using the raise keyword, allowing custom exceptions with specific messages to be thrown when particular conditions are met.

12:18, 10th November 2021

Increment and Decrement operators in Python

Unlike languages such as C++, Python does not support the ++ or -- increment and decrement operators, instead relying on the += and -= assignment operators, or equivalent arithmetic expressions such as x = x + 1 and y = y - 1. The += operator adds a specified value to a variable, making it useful for counters, loops and numeric updates, while -= subtracts a specified value, commonly applied in similar contexts such as tracking declining quantities.

Both operators work with numeric data types, though it is worth noting that -= cannot be used with strings and will raise a TypeError if attempted, whereas += can be used with strings to concatenate additional characters. These approaches are considered more explicit and readable than shorthand operators found in other languages, and they achieve the same practical outcomes when managing variables within everyday Python code.

16:38, 4th November 2021

Error: No CurrentVersion entry in Software/JavaSoft registry

When installing the xlsx package in R, users may encounter an error related to a missing CurrentVersion entry in the Software/JavaSoft registry, which typically occurs because the architecture of the installed Java version does not match that of the R installation. To resolve this, users should first verify their Java version by running java -version in the command prompt, then open RStudio and navigate to Tools, Global Options, and General Settings, where the R version can be changed to one that matches the architecture of the Java installation. Once the correct architecture is selected and the settings are applied, the package should load without further issues.

08:55, 2nd November 2021

How To Add Labels to Grouped Barplot with Bars Side-By-Side in R?

How to Annotate Bars in Grouped Barplot in Python?

The process of adding annotations to grouped barplots involves using specific functions within plotting libraries to display values directly on the bars. In R, ggplot2's annotate function allows for precise placement of text, with adjustments made to the height and position of labels to ensure clarity. Similarly, in Python, Matplotlib's annotate method is employed after generating a grouped barplot with Seaborn, where each bar's height and coordinates are accessed to place text accurately.

Customisations such as formatting numerical values and adjusting text positioning are common to enhance readability, ensuring annotations fit within the visual constraints of the plot. Both approaches require careful handling of data and visual elements to balance information density with aesthetic appeal.

12:47, 21st October 2021

SAS Problem Note 31278: Table 1 node generated by PROC REPORT

When PROC REPORT output is routed to ODS HTML, PDF or RTF destinations and a table of contents is generated, three default nodes are included: "The Report Procedure", "Detailed and/or summarized report" and "Table 1". Each of these nodes can be customised using specific SAS statements and options, with the first controlled via the ODS PROCLABEL statement, the second via the CONTENTS= option on the PROC REPORT statement and the third via the CONTENTS= option on the BREAK BEFORE statement. For PDF output, specifically, the PDFTOC option can be used to control how many levels of the table of contents are visible by default in the PDF reader.

  • The content, images, and materials on this website are protected by copyright law and may not be reproduced, distributed, transmitted, displayed, or published in any form without the prior written permission of the copyright holder. All trademarks, logos, and brand names mentioned on this website are the property of their respective owners. Unauthorised use or duplication of these materials may violate copyright, trademark and other applicable laws, and could result in criminal or civil penalties.

  • All comments on this website are moderated and should contribute meaningfully to the discussion. We welcome diverse viewpoints expressed respectfully, but reserve the right to remove any comments containing hate speech, profanity, personal attacks, spam, promotional content or other inappropriate material without notice. Please note that comment moderation may take up to 24 hours, and that repeatedly violating these guidelines may result in being banned from future participation.

  • By submitting a comment, you grant us the right to publish and edit it as needed, whilst retaining your ownership of the content. Your email address will never be published or shared, though it is required for moderation purposes.