This commit is contained in:
Even Bell 2025-03-21 10:16:52 +00:00
commit 27eeffee83
5 changed files with 108 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/.conda/

14
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,14 @@
/* VSCode */
{
"r.rpath.linux": ".conda/bin/R",
"r.rterm.linux": "${workspaceFolder}/.conda/bin/R",
"r.rterm.option": [
"--no-save",
"--no-restore"
],
"r.plot.useHttpgd": true,
"r.libPaths": [
".conda/bin/R/library"
],
"files.eol": "\n"
}

54
README.md Normal file
View File

@ -0,0 +1,54 @@
# Conda中的R语言环境
## 安装准备
- VSCode 代码编辑器
VSCode中插件扩展安装
- Python
- R
- R Debugger
- Miniconda/Anaconda 虚拟环境管理
> [!NOTE]
> 自行检查conda的镜像源配置以加速库的下载安装。
- Git 代码同步工具
## 操作步骤
0. 克隆本项目到指定的位置
`git clone https://git.unvec.site/stevenhobs/R-with-Conda <项目路径>`
1. 初始化conda虚拟环境
创建虚拟环境可以使用VSCode的Python解释器选择功能创建conda虚拟环境创建完虚拟环境后选择对应的虚拟环境使用conda安装对应的R依赖包
`conda install -c conda-forge r-base r-languageserver r-httpgd r-devtools radian`
或者使用命令创建虚拟环境并同时下载依赖包
`conda create -p .condarc -c conda-forge r-base r-languageserver r-devtools r-httpgd radian`
2. 初始化R Debugger
VSCode命令面板搜索执行 `R Debugger: Update or install the required R Package`进行安装R的VSC调试库
或者在R的控制台中执行指令
`devtools::install_github("ManuelHentschel/vscDebugger")`
> [!NOTE]
> 此操作需要访问Github平台以获取源码编译安装请确保 github.com 可正常访问
3. 库的安装
在当前的conda环境下
使用`conda search conda-forge::r-包名` 搜索对应的包
使用`conda install conda-forge::r-包名` 安装对应的包
或者采用R通用的安装CRAN

24
src/test-plot.R Normal file
View File

@ -0,0 +1,24 @@
# 设置随机种子以便重现
set.seed(123)
# 生成示例数据
x <- rnorm(100) # 生成 100 个正态分布随机数作为 x 值
y <- rnorm(100) # 生成 100 个正态分布随机数作为 y 值
# 创建散点图
plot(x, y,
main = "Scatter Plot of Random Data", # 图表标题
xlab = "X-axis Label", # X 轴标签
ylab = "Y-axis Label", # Y 轴标签
col = "blue", # 点的颜色
pch = 19
) # 点的形状
# 添加回归线
abline(lm(y ~ x), col = "red") # 添加线性回归线,红色
# 添加图例
legend("topright",
legend = c("Data Points", "Regression Line"),
col = c("blue", "red"), pch = c(19, NA), lty = c(NA, 1)
)

15
src/test-print.R Normal file
View File

@ -0,0 +1,15 @@
# 创建一个数字向量
numbers <- c(1, 2, 3, 4, 5)
print(numbers)
# 创建一个字符向量
fruits <- c("apple", "banana", "cherry")
print(fruits)
# 创建一个数据框
data <- data.frame(
Name = c("Alice", "Bob", "Charlie"),
Age = c(25, 30, 35),
Score = c(85.5, 90.0, 78.5)
)
print(data)