Initial commit - SolSolAutomazione project
This commit is contained in:
93
R-VsCode/r_vscode_quick_start.md
Normal file
93
R-VsCode/r_vscode_quick_start.md
Normal file
@@ -0,0 +1,93 @@
|
||||
# Quick Start: Testing R in VSCode
|
||||
|
||||
## Step 1: Install R Extensions
|
||||
1. Open VSCode
|
||||
2. Go to Extensions panel (Ctrl+Shift+X)
|
||||
3. Search for and install:
|
||||
- "R" by REditorSupport
|
||||
- "R Debugger" by RDebugger
|
||||
- "R LSP Client" by REditorSupport
|
||||
|
||||
## Step 2: Create Your First R File
|
||||
1. Create a new file (Ctrl+N)
|
||||
2. Save it with `.R` extension (e.g., `test.R`)
|
||||
3. Type some basic R code:
|
||||
```r
|
||||
print("Hello R!")
|
||||
x <- 1:5
|
||||
mean(x)
|
||||
```
|
||||
|
||||
## Step 3: Run R Code in VSCode
|
||||
### Method A: Using R Terminal
|
||||
1. Open Terminal in VSCode (Ctrl+` )
|
||||
2. Type `R` to start R interactive session
|
||||
3. Type commands directly:
|
||||
```r
|
||||
> 2 + 2
|
||||
[1] 4
|
||||
> plot(1:10)
|
||||
```
|
||||
|
||||
### Method B: Run Entire Script
|
||||
1. Open your `.R` file
|
||||
2. Press Ctrl+Shift+P
|
||||
3. Type "R: Run Source" and press Enter
|
||||
4. Output appears in R Terminal
|
||||
|
||||
### Method C: Run Selected Code
|
||||
1. Select code in your R file
|
||||
2. Right-click → "Run Selected Line(s)"
|
||||
3. Or use shortcut: Ctrl+Enter
|
||||
|
||||
## Step 4: View Plots
|
||||
1. Run plot commands in R terminal:
|
||||
```r
|
||||
plot(1:10, main="Test Plot")
|
||||
```
|
||||
2. Plots appear in VSCode's Plot viewer panel
|
||||
|
||||
## Step 5: Use R Markdown (Optional)
|
||||
1. Create new file with `.Rmd` extension
|
||||
2. Add code chunks:
|
||||
```r
|
||||
```{r}
|
||||
summary(mtcars)
|
||||
```
|
||||
```
|
||||
3. Click "Knit" button to render document
|
||||
|
||||
## Step 6: Debug R Code
|
||||
1. Set breakpoint by clicking left margin
|
||||
2. Press F5 to start debugging
|
||||
3. Step through code with F10/F11
|
||||
|
||||
## Quick Test Commands to Try
|
||||
In R terminal, test these:
|
||||
```r
|
||||
# Basic math
|
||||
2 + 2
|
||||
sqrt(16)
|
||||
|
||||
# Create data
|
||||
data <- c(1, 3, 5, 7, 9)
|
||||
mean(data)
|
||||
|
||||
# Simple plot
|
||||
plot(data, type="l", col="blue")
|
||||
|
||||
# Check packages
|
||||
installed.packages()[1:5,]
|
||||
```
|
||||
|
||||
## What You Should See
|
||||
- ✅ Code completion as you type
|
||||
- ✅ Syntax highlighting
|
||||
- ✅ R terminal with `>` prompt
|
||||
- ✅ Plots in separate viewer
|
||||
- ✅ Variable values in debugger
|
||||
|
||||
## Troubleshooting
|
||||
- If R isn't found: Check R path in extension settings
|
||||
- Restart VSCode after installing extensions
|
||||
- Ensure R is in system PATH
|
||||
32
R-VsCode/r_vscode_setup_guide.md
Normal file
32
R-VsCode/r_vscode_setup_guide.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Setting up R in VSCode
|
||||
|
||||
## Current Status
|
||||
✅ **R is installed**: Version 4.4.3 (2025-02-28) -- "Trophy Case"
|
||||
✅ **R executable**: `/usr/bin/R`
|
||||
|
||||
## Required VSCode Extensions
|
||||
|
||||
Install these extensions for optimal R development:
|
||||
|
||||
### Essential Extensions:
|
||||
1. **R Extension for Visual Studio Code** (by REditorSupport)
|
||||
- Provides syntax highlighting, code completion, and R integration
|
||||
- Install with: `codium --install-extension REditorSupport.r`
|
||||
|
||||
2. **R Debugger** (by RDebugger)
|
||||
- Debugging support for R scripts
|
||||
- Install with: `codium --install-extension RDebugger.r-debugger`
|
||||
|
||||
3. **R LSP Client** (by REditorSupport)
|
||||
- Language Server Protocol support for R
|
||||
- In VS Code, go to Extensions (Ctrl+Shift+X) and search for:
|
||||
"R LSP Client" by REditorSupport
|
||||
### Optional Extensions:
|
||||
- **R Markdown Preview** - For R Markdown files
|
||||
- **Quarto** - For modern R documents and reports
|
||||
|
||||
## Installation Commands
|
||||
|
||||
Run these commands to install the essential extensions:
|
||||
|
||||
|
||||
55
R-VsCode/test_r_script.R
Normal file
55
R-VsCode/test_r_script.R
Normal file
@@ -0,0 +1,55 @@
|
||||
# Test R Script for VSCode Setup
|
||||
# This script demonstrates basic R functionality
|
||||
|
||||
# Basic operations
|
||||
x <- 1:10
|
||||
y <- x^2
|
||||
|
||||
cat("=== Basic R Test ===\n")
|
||||
cat("Vector x:", x, "\n")
|
||||
cat("Vector y:", y, "\n")
|
||||
cat("Mean of x:", mean(x), "\n")
|
||||
cat("Sum of y:", sum(y), "\n")
|
||||
cat("Standard deviation of x:", sd(x), "\n\n")
|
||||
|
||||
# Data frame example
|
||||
df <- data.frame(
|
||||
id = 1:5,
|
||||
name = c("Alice", "Bob", "Charlie", "Diana", "Eve"),
|
||||
age = c(25, 30, 35, 28, 32),
|
||||
score = c(85, 92, 78, 96, 88)
|
||||
)
|
||||
|
||||
cat("=== Data Frame Example ===\n")
|
||||
print(df)
|
||||
cat("\n")
|
||||
|
||||
# Statistical summary
|
||||
cat("=== Statistical Summary ===\n")
|
||||
cat("Summary of scores:\n")
|
||||
print(summary(df$score))
|
||||
cat("\n")
|
||||
|
||||
# Simple function
|
||||
calculate_stats <- function(data) {
|
||||
list(
|
||||
mean = mean(data),
|
||||
median = median(data),
|
||||
min = min(data),
|
||||
max = max(data)
|
||||
)
|
||||
}
|
||||
|
||||
cat("=== Custom Function Test ===\n")
|
||||
stats <- calculate_stats(df$score)
|
||||
print(stats)
|
||||
cat("\n")
|
||||
|
||||
# Plot example (will create a plot if run in R)
|
||||
cat("=== Plot Information ===\n")
|
||||
cat("To create a plot, run this script in R and use:\n")
|
||||
cat("plot(x, y, main = 'Test Plot: y = x^2', type = 'b', col = 'blue')\n")
|
||||
cat("hist(df$score, main = 'Score Distribution', col = 'lightgreen')\n\n")
|
||||
|
||||
cat("✅ R script executed successfully!\n")
|
||||
cat("Your R environment is working correctly.\n")
|
||||
Reference in New Issue
Block a user