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语言编程
154
7
Linux
OSX
下的并行代码
如果你正在使用
Linux
或者
OS X
操作系统,以并行方式运行代码的另外一种
方式是使用 mclapply() mcmapply() 数:
#
这可以运行于
Windows
,但仅用了一个核
mclapply(1:N, snakes_ladders)
这些函数使用了分支(
fork
),就是说创建了正在运行线程的新复制品。然而,
Windows
系统不支持
Linux
下的这种底层功能mclapply() 的主要优点是你
不必启动和停止集群对象。最大缺点是在
Windows
电脑下,你被限制到单核上。
Rcpp
有时
R
就是慢,你尝试了各种方法而你的代码仍旧像老牛拉破车一样慢。
此时你应该考虑使用其他较快的语言编写代码的核心部分。通过
Rcpp
rJava
rPython
以及最近的
V8
之类的包,
R
提供了与其他语言的接口。这
些包分别提供了与
C++
Java
Python
JavaScript
语言的接口。
Rcpp
是其
中最流行的(见图
7-5
)。
C++
是一个现代的、快速的并具有较强支持度的语言,包含大量的计算各种
任务的库。
Rcpp
可轻松将
C++
融合到你的
R
工作流中。
尽管
C/Fortran
程序支持 .Call() 函数的调用形式,但不推荐这么用,因为使
.Call() 是一个痛苦的过程。
Rcpp
提供了一个友好的
API
,它允许你绕过
R
棘手的
C API
,编写高性能的代码。
C++
中典型瓶颈是地址循环与递归函数。
C++
是一门强大编程语言,有大量的书籍描述其内容。因此本节中重点关注 ...
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