RStudio Server Guide
Accessing RStudio Server
Internal Access (Institute Network):
- Server 01: http://r1.srils.cn/
- Server 02: http://r2.srils.cn/
External Access (From Internet):
- Server 01: http://r1.ext.srils.cn/
- Server 02: http://r2.ext.srils.cn/
Getting Started with RStudio
- Login: Use your server credentials
- Interface: Familiarize yourself with the 4-panel layout
- Source: Script editor
- Console: R command line
- Environment: Variables and data
- Files/Plots: File browser and output display
RStudio Features
- Integrated IDE: Complete R development environment
- Package Management: Easy installation and loading of R packages
- Version Control: Built-in Git support
- Publishing: Share analysis and reports
- Project Management: Organize work into projects
Example: R Data Analysis
# Load libraries
library(tidyverse)
library(ggplot2)
# Load and explore data
data <- read.csv("/data/sample_data.csv")
head(data)
summary(data)
# Data visualization
ggplot(data, aes(x = date, y = value)) +
geom_line() +
theme_minimal() +
labs(title = "Data Trends Over Time",
x = "Date",
y = "Value")
File Management in RStudio
Accessing Files
Via RStudio Interface:
- Use the Files panel (bottom-right by default)
- Navigate directories using the file browser
- Upload files using the “Upload” button
Via R Console:
# List files
list.files()
# Get current directory
getwd()
# Set working directory
setwd("/data/projects/my_project")
# Create directory
dir.create("new_folder")
Data Storage Locations
See the File Storage Guide for detailed information about data storage locations and file management.
Working with R Projects
Creating Projects
- New Project: File → New Project
- Choose Type:
- New Directory (fresh start)
- Existing Directory (use existing folder)
- Version Control (clone from Git)
Project Benefits
- Organization: Keep related files together
- Working Directory: Automatic path management
- Environment: Separate workspace for each project
- Version Control: Easy Git integration
Package Management
Installing Packages
# Install from CRAN
install.packages("package_name")
# Install multiple packages
install.packages(c("dplyr", "ggplot2", "readr"))
# Install from Bioconductor
if (!require("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("package_name")
Loading Packages
# Load single package
library(dplyr)
# Load multiple packages
library(tidyverse) # Loads multiple packages
# Check if package is installed
if (!require("package_name")) {
install.packages("package_name")
library(package_name)
}
Best Practices for RStudio
Code Organization
- Script Structure: Start with library loading, then functions, then main code
- Comments: Use
#for comments,#'for function documentation - Naming Conventions: Use snake_case for variables and functions
- Project Structure: Organize files in logical folders
Performance Optimization
- Memory Management: Use
rm()to remove large objects - Vectorization: Use vectorized operations instead of loops
- Data Types: Choose appropriate data types (factors, numerics)
- Parallel Processing: Use packages like
parallelorforeach
Data Security
- Regular Saves: Save scripts and workspaces frequently
- Version Control: Use Git for code versioning
- Data Privacy: Follow institutional data handling guidelines
- Backup: Regular backup of important projects
Troubleshooting RStudio
Common Issues
RStudio Connection Issues:
# Check RStudio Server status (contact admin)
sudo systemctl status rstudio-server
# Restart RStudio Server (contact admin)
sudo systemctl restart rstudio-server
R Session Problems:
- Session Crashed: Restart R session (Session → Restart R)
- Memory Issues: Clear workspace or restart session
- Package Errors: Check package installation and compatibility
Performance Issues:
- Check system resources with
htoportop - Close unused projects and clear large objects
- Restart R session to free memory
- Contact administrator for resource allocation
Error Diagnosis
# Check R version
R.version.string
# Check installed packages
installed.packages()
# Check memory usage
object.size(your_object)
gc() # Garbage collection
# Session information
sessionInfo()
Advanced Features
Markdown Reports
- R Markdown: Create dynamic reports mixing R code and text
- Knit: Generate HTML, PDF, or Word documents
- Shiny: Create interactive web applications
Version Control
- Git Integration: Built-in Git support in RStudio
- Commit: Track changes to your code
- Push/Pull: Sync with remote repositories
Publishing
- RPubs: Publish reports to RPubs
- Shiny Server: Deploy Shiny applications
- GitHub: Share code and collaborate
Getting Help
- RStudio Documentation: https://docs.rstudio.com/
- R Documentation: Use
?function_nameorhelp(function_name) - Community Forums: https://community.rstudio.com/
- Stack Overflow: Tag questions with
randrstudio - Server Administrator: Contact for technical issues
Back to: Apps Usage Guide
Need additional help? Contact the SRILS Server administration team for technical support.