Working in RStudio without Git integration

When you work in RStudio from a project that does not have integration with a Git repository, you can create R scripts and work with data assets from the project, but you can't add your R scripts to the project as script assets.

Working with data files

In RStudio, you can work with data files from different sources:

  • Files in the RStudio server file structure, which you can view by clicking Files in the lower right section of RStudio. This is where you can create folders, upload files from your local system, and delete files.

    To access these files in R, you need to set the working directory to the directory with the files. You can do this by navigating to the directory with the files and clicking More > Set as Working Directory.

    Be aware that files stored in the Home directory of your RStudio instance are persistent within your instance only and cannot be shared across environments nor within your project.

  • Data assets in the project, which you can view by clicking Files in the lower right section of RStudio. The data assets are in the folder called project_data_asset. You can select to view the content of a file or import the data set by clicking the asset.

    If you add a data file to this folder, the file is not added as a data asset to the project. To add data files as project data assets, see Adding project assets.

    It is not possible to open and view connected data assets cannot be in the project_data_asset directory. You can only access connected data assets programmatically from an R script in RStudio.

  • Data stored in a database system.

Loading and accessing data

Data loading options per compute engine type

Data loading options per compute engine type
Data loading options Anaconda R distribution R + Spark
Load data into a sparkSessionDataFrame
Load data into an R data frame

Generating code that loads data directly to RStudio

Loading data from local files

To generate code that inserts data from local files to RStudio:

  1. Click the Code snippets icon (the Code snippets icon) and then click Read data
  2. Select the data source from your project and then select Copy to clipboard.
  3. Paste the code in the RStudio file editor.

Supported file types:

  • CSV/delimited files
  • Excel files (.xls, .xlsx, .xlsm)
  • JSON files
  • SAS files

Loading data from data source connections

Before you can load data from an IBM data service or from an external data source, you must create or add a connection to your project. See Adding connections to projects.

To generate code that inserts data from database connections to RStudio:

  1. Click the Code snippets icon (the Code snippets icon) and then click Read data
  2. Select the connection from your project.
  3. Select the data source from the connection and then select Copy to clipboard.
  4. Paste the code in the RStudio file editor. The generated code serves as a quick start to begin working with a data set or connection. For production systems, carefully review the inserted code to determine whether you should write your own code that better meets your needs.
  5. If necessary, enter your personal credentials for locked data connections that are marked with a key icon (the key symbol for connections with personal credentials). This is a one-time step that permanently unlocks the connection for you. After you have unlocked the connection, the key icon is no longer displayed. See Adding connections to projects.
  6. If no code can be generated for the connection, load the credentials and open the database connection that references your credentials. Write code to load the data.

RStudio supports the same database connections as Jupyter notebooks. For details, see Data load support in notebooks.

Adding or deleting project assets

You should upload data files to use in RStudio by clicking the Upload asset to project icon (Shows the upload asset to project icon) on your project's Assets page because these files are automatically added as Data assets to your project.

However, if you uploaded or created data files in RStudio, you can add these files to your project as project data assets. These files must be in the /home/project_data_asset folder in RStudio. To add these files as data assets to the project:

  1. On the Assets page of the project, click Import assets.
  2. Select Project files and the file in the /home/project_data_asset folder that you want to add to the project as asset.

If you delete a data asset from the /home/project_data_asset folder in RStudio, you must delete the data asset in the project by:

  1. On the Assets page of the project, selecting the data asset you want to delete.
  2. Selecting Delete from the options list.

Working with prompts

If the watsonx.ai service is installed on your cluster, you can add various sample prompts for specific models into your R code. To add a sample prompt, click the Code snippets icon (the Code snippets icon), select Prompt Engineering, and browse the various categories to find a sample prompt. When you select a prompt, click Copy to clipboard and then paste the code in the RStudio file editor.

Learn more

Parent topic: RStudio