R support
Collaboratively build projects using R + SQL and share them in your workspace as you would with any other Hex project.
- Users will need Can Edit permissions.
Hex offers support for both Python and SQL projects. Additionally, for R users, Hex provides support for R and SQL projects, allowing you to create and share projects with your team while seamlessly mixing R and SQL. It's worth noting that R users have access to a subset of available cell types, and the "no code" cells are not available to them, unlike Python users. Therefore, we recommend opting for R and SQL projects if you have experience with R.
Hex projects can be Python + SQL or R + SQL. You cannot mix R and Python in a project.
Create an R project
To create a project that uses R & SQL, choose the "New R Project" option from the project creation dropdown menu.
Note that you cannot switch a project between languages after it is created.
Connect to and query data
You can browse available data sources or add a new one in the left sidebar and query them in a SQL cell like you would in any other Hex project.
Your SQL output will still be stored in a dataframe that can be referenced in other downstream R and SQL cells. Note that since Display tables and Chart cells are not supported in R projects, you will only see the 10 row preview of your query results.
Analyze query results with R
Since your SQL results are stored in a dataframe, you can query them again in subsequent SQL cells. This allows you to break up complex SQL logic like CTEs or nested subqueries into smaller, easier to manage cells. Read more about SQL chaining in our SQL Principles documentation. You can also reference the dataframe in downstream R cells.
The example below uses data connection SQL to query a table of Citibike trips in Manhattan from a connected data warehouse table. These results are stored in a dataframe, citibike_data
. The citibike_data
dataframe is then used in an R cell that calculates the distance between the starting and ending stations for each trip. The output of that R cell is then queried again using dataframe SQL in a subsequent SQL cell to view the new distance column. Read more about dataframe SQL here.
Visualize data with R
Although Chart cells are not supported in R, you can still visualize data using R libraries like Plotly or ggplot2.
Using R libraries
R projects come with a set of libraries pre-installed, which can be viewed in the pre-installed packages section of the **Environment tab in the **left sidebar**.
To use a library in your R project, add a new R cell and load the library using the standard library()
statement.
If the library you want to use is not already pre-installed, add a new R cell and use an install.packages()
statement to install it. Then use a library()
statement to load it into your project.
Hex Magic with R
While Hex Magic is available on all workspaces, Community plans are limited to 100 Magic actions per Editor/month.
Hex Magic is fully supported in R and SQL cells within R projects. You can use Magic to generate, edit, fix, explain, or explode (in SQL cells) code. Read more about Hex Magic here.
Building and publishing an app
You can curate pieces of your logic into an App using the App builder. Select the App tab at the top of your project, and drag cells from the outline on the left sidebar to add them to the app. You can rearrange and resize them as needed. Read more about building apps here.
Feature availability
R projects do not have parity with Python projects and do not support “no code” cells. This means that you cannot use Input Parameters, Charts, Transform, Data, and non-Markdown Text cells in R projects.
Supported features
Cell types
- SQL cells
- R cells
- Markdown (note: dynamic markdown is supported)
- Components
Development experience
-
Code formatting
-
Code completion (note: this works in most cases, with a few minor bugs, especially around completion of explicit function references like packageName::functionName)
-
hextoolkit (note: only the
write_dataframe
andquery_dataframes
methods are available. You cannot use hextookit methods to query your database connections) Run modes -
Dataframe SQL
-
Reactivity
Collaboration & sharing
- Multiplayer editing
- Commenting
- Publishing and sharing
- App creation
- Scheduled runs
Project navigation and management
- Data browser (note: browsing dataframe schemas is not supported)
- Environment sidebar
- File uploads
- Secrets (note: these will work for the vast majority of cases, but there are edge cases that will break. Variables with a preceding
_
are allowed in python, e.g._my_private_var
but not in R) - Hex built-in variables (
hex_scheduled
, etc.) - Environment variables
- Version history
- GitHub packages
- Statuses/categories