如何利用RStudio开发R包,并使用git同步到github中(How to)

作者按:

之前有过笔记,这次重新整理一下。只有以分享为目的的笔记,才会写的系统一点。之前的笔记,大半是自言自语,过一段时间,就忘记了当时的语境,也分不清自己到底说了什么。写作是锻炼思维的,一个人只有写的清楚,才能够想清楚,否则只是一时感悟,没有多少意义。

需要的软件

  • RStudio

可以从官网上下载RStudio软件

  • git

可以从官网上下周git软件,是命令行的软件

  • github账号

去github官网上注册一个用户名

1,github账号,新建一个project

比如命名为:2018test1,勾选下面的“Initialize this repository with a README”

创建完成之后,界面如下:

2, 设置git

比如我的账号为: myname, 邮箱为: myemail@163.com
在git终端下运行下面命令:

$ git config --global user.name "myname"
$ git config --global user.email myemail@163.com
$ ssh-keygen -t rsa -C "myemail@163.com" //邮箱同上

git会在C:\Users\Admin-pc.ssh 中生成两个文件, id_rsa 和 id_rsa.pub.

使用text 打开id_rsa.pub,复制里面的秘钥,放到github中 SSH and GPG keys, 打开方法:

  • 打开github,点击头像,然后点击Setting
    在这里插入图片描述

  • 在左边选择 SSH and GPG keys
    在这里插入图片描述

  • 点击 New SSH key,将 id_rsa.pub的内容复制进去即可
    在这里插入图片描述

3, 设置RStudio

  • 新建一个git项目
    在这里插入图片描述

  • 将github中的项目网址,复制到红框中
    在这里插入图片描述

  • 点击Tools,选择Options, 点击Creat RSA Key, 然后点击 View public key, 复制框内的内容到github中的SSH and GPG keys 中.
    在这里插入图片描述

  • 将内容复制到SSH and GPG keys中
    在这里插入图片描述

4, 将RStudio中的内容同步到github中

  • 新建一个2018code的文件
    在这里插入图片描述

  • commit, 勾选需要上传的内容
    在这里插入图片描述

  • 点击push
    在这里插入图片描述

  • 上传完成,显示
    在这里插入图片描述

github中查看同步的内容

在这里插入图片描述

可以看出,设置成功!

在这里插入图片描述

### LightGBM R Package Installation For installing the LightGBM R package, one can follow a series of specific instructions that differ slightly from Python-based installations. The process involves ensuring certain prerequisites are met before proceeding with the actual installation. To begin, it is necessary to have R and RStudio installed on the system along with some essential libraries such as `Rtools` which provides tools required for building packages under Windows environment[^4]. After setting up these requirements, users may proceed by cloning the official LightGBM repository using Git or downloading directly from GitHub: ```bash git clone --recursive https://github.com/microsoft/LightGBM.git ``` Once cloned, navigate into the root directory of LightGBM where configuration files reside. For Unix-like systems including macOS and Linux distributions like Ubuntu 18.04, executing shell scripts provided within this folder will handle dependency management automatically while configuring compilation options suitable for GPU support if desired[^5]. After successful completion of previous steps, move towards compiling C++ sources through invoking Makefile present inside build directories created during setup phase: ```bash cd LightGBM mkdir build && cd build cmake .. make -j$(nproc) ``` With compiled binaries ready, switch focus onto integrating them with R via its interface layer found at `R-package`. Here lies an important file named `install_gbm.R`, responsible not only for linking against native components but also managing additional runtime dependencies mentioned earlier (e.g., libomp)[^6]: ```r setwd("path/to/your/cloned/repo/R-package") source('install_lightgbm.R') ``` Upon execution without errors, congratulations! One has successfully integrated LightGBM capabilities into R sessions locally. ### Usage Example Below demonstrates how to load data sets, train models, make predictions, evaluate performance metrics all utilizing functions exposed by LightGBM's API in R context: ```r library(lightgbm) data(agaricus.train, package = "lightgbm") train_data <- lgb.Dataset(agaricus.train$data, label = agaricus.train$label) params <- list(objective = "binary", metric = "auc") model <- lgb.train(params, train_data, 20) pred <- predict(model, agaricus.test$data) cat("Accuracy:", mean((pred > 0.5) == agaricus.test$label), "\n") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值