Skip to Content
R在数据科学中的应用,第2版
book

R在数据科学中的应用,第2版

by Hadley Wickham, Mine Cetinkaya-Rundel, Garrett Grolemund
May 2025
Intermediate to advanced
578 pages
8h 9m
Chinese
O'Reilly Media, Inc.
Content preview from R在数据科学中的应用,第2版

第 8 章 工作流程 工作流程:获取帮助

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

本书不是一座孤岛;没有任何一种资源可以让你掌握 R。当你开始将本书中介绍的技术应用到自己的数据中时,你很快就会发现我们没有回答的问题。本节将介绍一些获得帮助的技巧,帮助你不断学习。

谷歌是您的朋友

如果遇到困难,可以从 Google 开始。通常情况下,在查询中添加 "R "就足以将其限制在相关结果中:如果搜索没有用处,通常意味着没有任何特定于 R 的结果可用。此外,添加诸如 "tidyverse "或 "ggplot2 "之类的软件包名称也有助于缩小搜索结果的范围,使之指向您感觉更熟悉的代码,例如 "如何用 R 制作方框图 "与 "如何用 ggplot2 在 R 中制作方框图"。Google 对于错误信息尤其有用。如果你收到一条错误信息,却不知道它是什么意思,可以试着谷歌一下!很有可能以前也有人遇到过这种情况,网络上一定会有帮助。(如果错误信息不是英文的,请运行Sys.setenv(LANGUAGE = "en") 并重新运行代码;您更有可能找到英文错误信息的帮助)。

如果 Google 没有帮助,可以试试Stack Overflow。首先花一点时间搜索现有答案,包括[R] ,将搜索范围限制在使用 R 的问题和答案上。

制作 reprex

如果你在谷歌上找不到任何有用的东西,那么准备一个reprex(最小可重现 示例的简称)是一个非常好的主意。一个好的 reprex 会让其他人更容易帮助你,而且在制作过程中,你自己也会发现问题所在。创建 reprex 有两个部分:

  • 首先,您需要使您的代码具有可重现性。这意味着你需要捕获所有内容,即包括任何 library()调用并创建所有必要的对象。要确保做到这一点,最简单的方法就是使用 reprex 软件包。

  • 其次,你需要将其最小化。剔除所有与问题不直接相关的内容。这通常需要创建一个比现实生活中更小更简单的 R 对象,甚至使用内置数据。

这听起来很费劲!是很辛苦,但回报也很丰厚:

  • 80% 的情况下,创建一个出色的示例可以揭示问题的根源。编写一个自成一体的简明示例的过程往往能让你回答自己的问题,这真是令人惊叹。

  • 在另外 20% 的时间里,你会以一种易于他人发挥的方式抓住问题的本质。这将大大增加你获得帮助的机会!

手工创建 reprex 时,很容易不小心遗漏某些内容,这意味着您的代码无法在他人的计算机上运行。使用 reprex 软件包可以避免这个问题,该软件包已作为 tidyverse 的一部分安装。比方说,你将这段代码复制到剪贴板上(或在 RStudio 服务器或 Cloud 上选择它):

y <- 1:4
mean(y)

然后调用reprex() ,默认输出格式为 GitHub 格式:

reprex::reprex()

在 RStudio 的浏览器(如果您在 RStudio 中)或默认浏览器中将显示渲染精美的 HTML 预览。reprex 会自动复制到您的剪贴板(在 RStudio 服务器或 Cloud 上,您需要自己复制):

``` r
y <- 1:4
mean(y)
#> [1] 2.5
```

这些文本以一种特殊的方式格式化,称为 Markdown,可以粘贴到 StackOverflow 或 GitHub 等网站上,这些网站会自动将其呈现为代码的样子。下面是 Markdown 在 GitHub 上的呈现效果:

y <- 1:4
mean ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

R深度学习权威指南

R深度学习权威指南

Posts & Telecom Press, Joshua F. Wiley
AI工程

AI工程

Chip Huyen
Raku学习手册

Raku学习手册

brian d foy

Publisher Resources

ISBN: 9798341657304