datapasta包提供了RStudio插件和函数,可以自由地复制粘贴网页等其他来源的数据表到RStudio中。
安装
下载: install.packages("datapasta") 设置快捷方式:Tools -> Addins -> Browse Addins,然后点击Keyboard Shortcut
基本用法
使用tribble_paste()将表格粘贴为tibble,可以使用快捷键Ctrl Shift T。
粘贴为
代码语言:javascript复制tibble::tribble(
~ExonIntron, ~g_Description, ~c_Description, ~AvgHet, ~SNPlink, ~Effect,
"4-exon", "g.11333C>A", "c.102C>A", "-", 11575998L, "silent",
"4-exon", "g.11339G>A", "c.108G>A", "0.012738", 1800370L, "silent",
"4-exon", "g.11370C>T", "c.139C>T (P47S)", "0.029329", 1800371L, "missense",
"4-exon", "g.11446C>G", "c.215C>G (R72P)", "0.492248", 1042522L, "missense",
"6-exon", "g.12708A>G", "c.639A>G", "0.023526", 1800372L, "silent"
)
将list粘贴为向量
list可以是表格或中间输出的行或列,使用Paste as vector快捷键粘贴。 例如,
代码语言:javascript复制Mint Fedora Debian Ubuntu OpenSUSE##orMint, Fedora, Debian, Ubuntu, OpenSUSE##orMintFedoraDebianUbuntuOpenSUSE
通过crtl alt shift v或ctrl shift v可粘贴为,
代码语言:javascript复制c("Mint", "Fedora", "Debian", "Ubuntu", "OpenSUSE")
##适用于于长向量
c("Mint",
"Fedora",
"Debian",
"Ubuntu",
"OpenSUSE")
在R中输出数据
使用dpasta()输出到R。 dpasta()接受tibbles、data.frames和vector。数据匹配输入中的格式输出。
代码语言:javascript复制iris %>%
head() %>%
dpasta()
输出
代码语言:javascript复制data.frame(
Sepal.Length = c(5.1, 4.9, 4.7, 4.6, 5, 5.4),
Sepal.Width = c(3.5, 3, 3.2, 3.1, 3.6, 3.9),
Petal.Length = c(1.4, 1.4, 1.3, 1.5, 1.4, 1.7),
Petal.Width = c(0.2, 0.2, 0.2, 0.2, 0.2, 0.4),
Species = as.factor(c("setosa", "setosa", "setosa", "setosa", "setosa",
"setosa"))
)
或者
代码语言:javascript复制mpg %>%
select(-class) %>%
head() %>%
dpasta()
输出
代码语言:javascript复制tibble::tribble(
~manufacturer, ~model, ~displ, ~year, ~cyl, ~trans, ~drv, ~cty, ~hwy, ~fl,
"audi", "a4", 1.8, 1999L, 4L, "auto(l5)", "f", 18L, 29L, "p",
"audi", "a4", 1.8, 1999L, 4L, "manual(m5)", "f", 21L, 29L, "p",
"audi", "a4", 2, 2008L, 4L, "manual(m6)", "f", 20L, 31L, "p",
"audi", "a4", 2, 2008L, 4L, "auto(av)", "f", 21L, 30L, "p",
"audi", "a4", 2.8, 1999L, 6L, "auto(l5)", "f", 16L, 26L, "p",
"audi", "a4", 2.8, 1999L, 6L, "manual(m5)", "f", 18L, 26L, "p"
)