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语言编程
高效编程
73
watch = stop_watch()
watch 对象是包含两个函数的列表。一个函数用于启动计时:
watch$start()
另外一个用于停止定时器:
watch$stop()
如果不使用函数闭包,秒表函数将非常长、复杂,当然也很低效。应用得当,
函数闭包是编写简洁代码的非常有用的工具。
练习
1.
不使用函数闭包编写一个秒表函数。
2.
很多秒表除了可测量你的总时间,还可测量你一圈时间。在前面的 stop_
watch() 中增加 lap() 数,用来记录个体时间,同时保留记录总时间功能。
一个与函数闭包相关的概念是非标准化评估(
NSE
),或编程语言,
R
中总
是会遇到
NSE
的问题。例如,我们执行 plot(height, weight)
R
自动地
x
轴标为高度,
y
轴标为宽度。这是一个很强大的概念,能帮我们简化代码。
详见
Hadley Wickham
的《
Advanced R
》(
CRC Press
)一书中的”
Nonstandard
evaluation
”小节。
字节编译
R
的核心成员
Luke Tierney
编写的
compiler
包自
2.13.0
版后成为
R
的一部
分。
compiler
包可将函数编译成字节代码,从而函数运行更快
1
。编译过程
清除了大量解释器必须执行的耗时操作,例如变量查询。
自从
2.14.0
版,所有基础
R
中的标准函数和包均被预编译成字节代码。这可
通过基本函 mean() 验证:
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