当前位置: 首页 > news >正文

使用GPT让你的RStudio如虎添翼

API的的调用目前来说不限制地区,但是OpenAI的API的申请限制了地区。运行的时候,如果出现了429,意味着你被限流了,需要等一会才行。

前提是,你需要注册一个OpenAI的账户,然后在https://openai.com/api/ 里申请OpenAI的密钥。

在页面左上角,点击头像,选择View API Keys

在这里插入图片描述

然后新建一个密钥,并复制。

接着,我们需要在R语言中设置一个环境变量OPENAI_API_KEY。

这有两种方式,一种是每次启动RStudio后手动运行如下代码

Sys.setenv(OPENAI_API_KEY = "你复制的密钥")

另一种是利用usethis包,通过如下代码在项目目录下创建一个.Renviron文件

library(usethis)
usethis::edit_r_environ(scope = "project")

在该文件中设置OPENAI_API_KEY,并保存该文件。

在这里插入图片描述

之后从github上安装gptstudio

#install.packages("devtools")
devtools::install_github("MichelNivard/gptstudio")

安装完毕后,你的RStudio中的Addins就会出现GPTSTUDIO工具栏

在这里插入图片描述

如我们所见,它的功能主要有7项。

我们可以让它帮我们写代码,例如你写了一段注释,

# write a R code for volcano plot with result from 
# DESeq2

然后选择插件的Write/Code from prompt,过了一会就能生成如下的代码

# install and load the DESeq2 package
install.packages("DESeq2")
library(DESeq2)# read the data
data <- read.csv("data.csv")# create a DESeqDataSet
dds <- DESeqDataSetFromMatrix(countData = data,colData = data$condition,design = ~ condition)# run the DESeq2
dds <- DESeq(dds)# extract the results
res <- results(dds)# create the volcano plot
plot(res$log2FoldChange, -log10(res$padj),xlab = "log2 Fold Change",ylab = "-log10 Adjusted p-value",main = "Volcano Plot")# add points
points(res$log2FoldChange, -log10(res$padj),pch = 20,col = ifelse(res$padj < 0.05, "red", "black"))# add lines
abline(h = -log10(0.05), lty = 2, col = "blue")
abline(v = 0, lty = 2, col = "blue")

此外,可以让它帮我们给代码写注释,比如说你在Rstudio中输入如下内容,

set.seed(1)
mtcars2 <- transform(mtcars, mpg = ifelse(runif(32) < 0.2, NA, mpg))
ggplot(mtcars2, aes(wt, mpg)) +geom_point()

选择代码后,在Addins中选择了 Comment your code,我们就会得到如下的内容。

# load the ggplot2 package
library(ggplot2)
# set the seed for the random number generator
set.seed(1)
# create a new variable called mtcars2, which is a copy of the mtcars dataset
# with 20% of the mpg values replaced with NA
mtcars2 <- transform(mtcars, mpg = ifelse(runif(32) < 0.2, NA, mpg))
# create a scatterplot of mpg vs wt, with mpg on the y-axis and wt on the x-axis
ggplot(mtcars2, aes(wt, mpg)) +geom_point()

其他功能可以通过官方文档进行了解哦https://github.com/MichelNivard/gptstudio

http://www.lryc.cn/news/6710.html

相关文章:

  • Python 算法交易实验45 再探量化
  • Dubbo加载配置文件方式,加载流程,加载配置文件源码解析
  • 十大开源测试工具和框架,一定有你需要的
  • 加密技术在android中的应用
  • 备战蓝桥杯【一维前缀和】
  • 研报精选230214
  • 【SSL/TLS】准备工作:证书格式
  • Linux常用命令---系统常用命令
  • C 结构体
  • 手语检测识别
  • android fwk模块之Sensor架构
  • 安装less-loader5出现webpack版本不兼容
  • Java 网络编程
  • BEV学习记录
  • Webrtc Native C++切换音频输入源
  • 裸辞5个月,面试了37家公司,终于找到理想工作了
  • Mybatis-plus@DS实现动态切换数据源应用
  • SpringBoot的创建和使用
  • 居家电话客服宝典
  • 开发方案设计
  • 文件路径模块pathlib
  • spring cloud篇——什么是服务熔断?服务降级?服务限流?spring cloud有什么优势?
  • Tomcat构建
  • 入门深度学习——基于全连接神经网络的手写数字识别案例(python代码实现)
  • 预算砍砍砍,IT运维如何降本增效
  • 10.Jenkins用tags的方式自动发布java应用
  • 2023新华为OD机试题 - 相同数字的积木游戏 1(JavaScript)
  • 重构之改善既有代码的设计(一)
  • Kotlin data class 数据类用法
  • 随笔-老子不想牺牲了