From b9c57d54d2720d835a2e3df5cb8d0b554edc1c9f Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Mon, 4 Sep 2023 20:27:37 +0800 Subject: [PATCH] Add support for r --- README.md | 4 ++-- chsrc.c | 19 +++++++++++++------ chsrc.h | 3 ++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0038b74..d8c2234 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # chsrc -全平台命令行换源工具,**目标支持 Linux, Windows, macOS, BSD 等所有操作系统,飞腾,龙芯等所有CPU**。 +全平台命令行换源工具,**目标支持 Linux, Windows, macOS, BSD 等所有操作系统,龙芯、申威、飞腾、兆芯、海光等所有CPU**。 若有不支持的情况,请提交issue。 @@ -41,7 +41,7 @@ set # 换源,指定使用某镜像站 - [ ] `chsrc set rust` 或 `chsrc set cargo` 或 `chsrc crate` - [ ] `chsrc set java` 或 `chsrc set maven` 或 `chsrc set mvn` 或 `chsrc gradle` -- [ ] `chsrc set r` 或 `chsrc set cran` +- [x] `chsrc set r` 或 `chsrc set cran` - [ ] `chsrc set julia` ## 操作系统 diff --git a/chsrc.c b/chsrc.c index 1b71fd2..bc8fcf3 100644 --- a/chsrc.c +++ b/chsrc.c @@ -627,16 +627,23 @@ pl_java_setsrc (char* option) } -/* TODO: 暂未实现 */ + void pl_r_getsrc (char* option) { - // char* cmd = "npm config get registry"; - // system(cmd); + char* cmd = NULL; + if(xy_on_windows) { + cmd = "type %USERPROFILE%\\Documents\\.Rprofile"; + } else { + cmd = "cat ~/.Rprofile"; + } + chsrc_logcmd(cmd); + system(cmd); } /** * R 换源,参考:https://help.mirrors.cernet.edu.cn/CRAN/ + * TODO: bioconductor 换源 */ void pl_r_setsrc (char* option) @@ -655,12 +662,12 @@ pl_r_setsrc (char* option) const char* file = xy_strjoin (3, "options(\"repos\" = c(CRAN=\"", source.url, "\"))" ); char* cmd = NULL; - // TODO: 待确认,Windows 下是否也是该文件 if (xy_on_windows) - cmd = xy_strjoin(3, "echo ", file, " >> %USERPROFILE%/.Rprofile"); + cmd = xy_strjoin(3, "echo ", file, " >> %USERPROFILE%/Documents/.Rprofile"); else cmd = xy_strjoin(3, "echo ", file, " >> ~/.Rprofile"); + chsrc_logcmd(cmd); system(cmd); chsrc_say_thanks(&source); } @@ -931,7 +938,7 @@ target_info pl_dotnet_target = {pl_dotnet_setsrc, NULL, pl_dotnet_sources, pl_dotnet_sources_n}, pl_java_target = {pl_java_setsrc, NULL, pl_java_sources, pl_java_sources_n}, pl_php_target = {pl_php_setsrc, pl_php_getsrc, pl_php_sources, pl_php_sources_n}, - pl_r_target = {pl_r_setsrc, NULL, pl_r_sources, pl_r_sources_n}, + pl_r_target = {pl_r_setsrc, pl_r_getsrc, pl_r_sources, pl_r_sources_n}, pl_julia_target = {pl_julia_setsrc, NULL, pl_julia_sources, pl_julia_sources_n}; diff --git a/chsrc.h b/chsrc.h index ecf134a..362d59b 100644 --- a/chsrc.h +++ b/chsrc.h @@ -189,7 +189,7 @@ pl_perl_sources[] = { /** - * 2023-08-30 更新 + * 2023-09-04 更新 * * TODO: 速度未经测试,请R用户协助 */ @@ -197,6 +197,7 @@ pl_r_sources[] = { {&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/cran/"}, {&Ali, "https://mirrors.aliyun.com/CRAN/"}, {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/CRAN/"}, + {&Sustech, "https://mirrors.sustech.edu.cn/CRAN"}, {&Bfsu, "https://mirrors.bfsu.edu.cn/CRAN/"}, {&Bjtu, "https://mirror.bjtu.edu.cn/cran/"}, },