init
This commit is contained in:
8
.Rprofile
Normal file
8
.Rprofile
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# R 配置
|
||||||
|
|
||||||
|
options("repos" = c(CRAN = "https://mirrors.cernet.edu.cn/CRAN/")) # 包的镜像源
|
||||||
|
|
||||||
|
if (Sys.getenv("VSCODE_DEBUG_SESSION") == "1") { # Debugger关联
|
||||||
|
Sys.setenv(TERM_PROGRAM = "vscode")
|
||||||
|
source(file.path(Sys.getenv(if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"), ".vscode-R", "init.R"))
|
||||||
|
}
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/.conda/
|
5
.lintr
Normal file
5
.lintr
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
linters: linters_with_defaults(
|
||||||
|
line_length_linter(120),
|
||||||
|
object_usage_linter = NULL,
|
||||||
|
commented_code_linter = NULL
|
||||||
|
)
|
27
.vscode/settings.json
vendored
Normal file
27
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/* VSCode 项目配置 */
|
||||||
|
{
|
||||||
|
"r.rpath.linux": "${workspaceFolder}/.conda/bin/R",
|
||||||
|
"r.rterm.linux": "${workspaceFolder}/.conda/bin/radian",
|
||||||
|
"r.rterm.option": [
|
||||||
|
"--no-save",
|
||||||
|
"--no-restore",
|
||||||
|
"--r-binary=${workspaceFolder}/.conda/bin/R"
|
||||||
|
],
|
||||||
|
"r.plot.useHttpgd": true,
|
||||||
|
"r.lsp.diagnostics": true,
|
||||||
|
"r.alwaysUseActiveTerminal": true,
|
||||||
|
"r.bracketedPaste": true,
|
||||||
|
"r.sessionWatcher": true,
|
||||||
|
"[r]": {
|
||||||
|
"editor.defaultFormatter": "REditorSupport.r",
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[rmd]": {
|
||||||
|
"editor.defaultFormatter": "REditorSupport.r",
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
// "terminal.integrated.defaultProfile.linux": "R Terminal", # 终端默认开启 R终端
|
||||||
|
"files.eol": "\n",
|
||||||
|
"editor.tabSize": 2,
|
||||||
|
"editor.detectIndentation": false
|
||||||
|
}
|
53
README.md
Normal file
53
README.md
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# Conda中的R语言环境
|
||||||
|
|
||||||
|
## 安装前提
|
||||||
|
|
||||||
|
- Linux / MacOS / WSL 系统
|
||||||
|
|
||||||
|
- VSCode 代码编辑器
|
||||||
|
|
||||||
|
插件扩展安装:
|
||||||
|
|
||||||
|
- R
|
||||||
|
- R Debugger
|
||||||
|
|
||||||
|
- Miniforge / Miniconda / Anaconda 虚拟环境管理
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> 自行检查conda的镜像源配置,以加速库的下载安装。
|
||||||
|
|
||||||
|
- Git 代码同步工具
|
||||||
|
|
||||||
|
## 操作步骤
|
||||||
|
|
||||||
|
0. 克隆本项目到指定的位置
|
||||||
|
|
||||||
|
`git clone https://git.unvec.site/stevenhobs/R-with-Conda <项目路径>`
|
||||||
|
|
||||||
|
1. 初始化conda虚拟环境
|
||||||
|
|
||||||
|
`conda create -p .conda -c conda-forge r-base r-languageserver r-devtools r-httpgd r-rlang r-jsonlite radian`
|
||||||
|
|
||||||
|
2. 初始化R语言调试器,两种方式任选其一
|
||||||
|
|
||||||
|
- 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 命令
|
||||||
|
|
||||||
|
查找包 `conda search -p .conda -c conda-forge r-包名`;
|
||||||
|
|
||||||
|
安装包 `conda install -p .conda -c conda-forge r-包名`;
|
||||||
|
|
||||||
|
- 采用R控制台命令安装`install.packages()`
|
||||||
|
- VSCode R扩展提供的包管理视图
|
24
src/test-plot.R
Normal file
24
src/test-plot.R
Normal 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
15
src/test-print.R
Normal 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)
|
Reference in New Issue
Block a user