Farewell C#, Welcome R

The last three toy projects showcased on this blog are Arithmetic Trainer, Achievement Quantifier, and Noter.
Besides being written in C#, the commonality between all three is involvement of randomness. Arithmetic Trainer generates random practice questions. Achievement Quantifier uses AutoFixture to generate random data for unit testing. Noter uses Bogus to generate and import random data into the database for manual testing.
With randomness appearing repeatedly, it is worth exploring specialised tools. One among many such tools is the R programming language.
From the perspective of a newcomer to R, this post provides an overview of R and compares it to C#.
Tasks & Purpose
R is a statistical programming language. It excels at statistical modelling, conducting hypothesis testing, estimating confidence intervals, doing data visualisation, data manipulation, predictive modelling, and other related tasks.
C# is a general-purpose programming language. It excels in web development (ASP.NET Core), cross-platform desktop applications (Avalonia), game development (Unity), and many other applications.
IDEs
The main IDE for R is RStudio. The four primary panes in RStudio, from the top-left corner and counterclockwise, are Source, Console, Output, and Environments:

Here are the top five most useful RStudio keyboard shortcuts:
Option+-
to insert the assignment operator, i.e. " <- "Cmd+Return
to run the current line/selectionCmd+Shift+C
to comment/uncomment the current line/selectionTab
to attempt completionCtrl+L
to clear the console
A more comprehensive list can be found, for example, here.
Other IDE options include VSCode and Jupyter notebooks. For C#, the IDE options include Rider, VSCode, Visual Studio (Windows only), and others.
Code Organisation
The code organisation levels equivalent to a single Git repository are projects in R and solutions in C#. Both are simply directories containing .Rproj
and .sln
files, respectively.
The first commit provides an example of an empty R project.
Subdividing further, C# solutions are organised into projects, namespaces, and classes. These organisational tools support codebases ranging from a few hundred to many millions of lines.
In contrast, R code is typically contained within a single file, representing a script that runs a complete analysis or experiment. At least, this is true from a beginner's perspective.
The second commit provides an example of such an analysis script. In 28 lines of code, it implements the prime-counting function using the Sieve of Eratosthenes algorithm, then plots the results for the first 200 positive integers.
Code Distribution
Both languages offer equivalent ways to distribute packages. In R, it is CRAN. In C#, it is NuGet.
In R, packages can be installed using the function install.packages('<PackageName>')
or via RStudio’s visual interface.
Similarly, in C#, packages can be installed via terminal with dotnet add package <PackageName>
or through visual interfaces.
Documentation
In terms of documentation, R is local-first. Calling ?
or the equivalent help
function in RStudio opens the help page for the given argument. For example, help pages for dput
, %in%
, and ??
can be opened with ?dput
, ?"%in%"
, and ?"??"
, respectively.
In contrast, C# can be considered web-first, with extensive documentation, tutorials, and guides available via Microsoft Learn.
Conclusion
This post has explored the tools surrounding R, compared it to C#, and showcased a simple R script. With this foundation established, the path is set to continue exploring everything R has to offer.