June 1, 2017 | James
Welcome to the second blog in my series looking at using the R programming language as a researcher, and how it can enhance the productivity and reproducibility of your research. If you’ve not read the first instalment – R for Researchers: practical data analysis in AnalytiXagility – you might want to read that one first.
This second blog post covers a few of the features unique to R in AnalytiXagility, our data analysis platform which comes complete with a built-in R console, and future posts will be covering a selection of cheatsheets for researchers from two of the vast range of R documentation and resources available online.
So, what is different when it comes to working with R in AnalytiXagility, rather than outside it? In general, nothing at all! When interacting with the built-in R console and running scripts, the methods will be instantly recognisable to anyone who has used R before, with a few important, simple, exceptions.
Using the AnalytiXagility R console requires you to interact with files, be they data tables, scripts or other file types, that are within your collaborative workspace in the platform. If you have a data table that you want the R console to read and analyse, you need to point the console to this file using AnalytiXagility-specific functions. These are functions that have been written using existing packages to allow the built-in database of files to be accessed by the R console. These functions are simple and analogous to many functions normally used in R, and they can be listed by typing:
into the R console to display the current R objects in memory. The listed functions can be incorporated into your R scripts in the place of their “normal” equivalent. For example, in the case of interacting with a data table, you can use the function:
to return a list of the available data tables within that workspace, and
to return the contents of a table. Functions such those that interact with the database “under the hood” are using the RPostgreSQL package, so if you are an advanced user you can customise these interactions to your specific requirements, rather than using the built-in functions.
The packages found in the CRAN repository are represented and updated regularly in AnalytiXagility, so any package you would want to use can be called by using the
library() function at the beginning of your code just like in a regular R script. Any packages not in CRAN, and therefore not already installed, can be installed using:
One final thing to mention when running your scripts in AnalytiXagility is don’t forget about the context sensitive sidebar! When using the R console, the righthand sidebar lists all available scripts that you have in your workspace; if you hover your mouse over a script you would like to run, an arrow appears on the right of it. Simply click this arrow, and press enter, and you will have run that script in the console without any copying and pasting. This is very useful for long, complex scripts, and is quite the time-saver.
Over the next few months we’ll be adding lots of new videos showing you how to perform different tasks in AnalytiXagility, but in the meantime if you have any questions or would like to know how to perform a specific task, please leave a comment below – we like a challenge and your query could form the basis of our next blog post!Tweet