Skip to Content
高效R语言编程
book

高效R语言编程

by Colin Gillespie, Robin Lovelace
August 2018
Intermediate to advanced
227 pages
4h 16m
Chinese
China Electric Power Press Ltd.
Content preview from 高效R语言编程
140
7
浪费到优化错误瓶颈对应的代码片段上。为了改进代码运行速度,至关重要
的是首先确定哪段代码是瓶颈。这就是代码分析的目的。
Rprof() 函数是一个分析
R
表达式执行情况的内置工具。在规则的时间间隔中,
该工具停下
R
解释器,记录当前函数调用堆栈并将相应信息保存到文件中。
Rprof() 的结果是不确定的。每次执行同一
R
函数时,外部环境都有所改变。
因此,每次你分析你的代码,测试结果会有稍微差异。
不幸的是,Rprof() 使用不便。基于这个原因,我们推荐使用
profvis
包来分
析你的
R
代码。
profvis
提供了交互式图形界面,能可视化显示 Rprof() 的分
析结果。
开始
profvis
安装完
profvis
(例如使 install.packages("profvis") 命令)
,
就可用其
分析
R
代码。我们使用 movies 数据集来举一个简单例子,该数据集中包含大
60000
部电影信息。首先,我们选择喜剧类的电影,而后绘制了电影创作
年与电影评级,并绘制了一个局部多项式回归线来识别相应趋势。
profvis
中的主要函数是 profvis(), 该函数分析代码并生成交互式
HTML
页面的分
析结果。profvis() 的第一个参数是要测试的
R
表达式。可以有很多行:
library("profvis")
profvis({
data(movies, package = "ggplot2movies") #
加载数据
movies = movies[movies$Comedy == 1,] ...
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进行数据清理、分析与可视化

迈克尔 弗里曼, 乔尔 罗斯
R数据科学

R数据科学

Hadley Wickham, Garrett Grolemund

Publisher Resources

ISBN: 9787519820855