bil*_*999 5 parallel-processing macos r ggplot2 gganimate
我的问题是如何利用 iMac 的多个核心来使 gganimate 运行得更快。还有另一个问题(更多链接在下面)询问同样的事情\xe2\x80\x94我的问题是关于这个问题的答案:加速 gganimate Rendering。
\n在该答案中,Roman 和 mhovd 指出了此GitHub 评论中的一个示例(另请参阅此 GitHub 帖子):
\nlibrary(gganimate)\nlibrary(future)\n\nanim <- ggplot(mtcars, aes(mpg, disp)) +\n transition_states(gear, transition_length = 2, state_length = 1) +\n enter_fade() +\n exit_fade()\n\nfuture::plan("sequential") ## default\nt0 <- system.time(animate(anim))\nprint(t0)\n\nfuture::plan("multiprocess", workers = 4L)\nt1 <- system.time(animate(anim))\nprint(t1)\nRun Code Online (Sandbox Code Playgroud)\n我已经尝试过这个,但得到的时间彼此非常接近:
\n user system elapsed \n1.0041475 0.9775679 0.9995509 \nRun Code Online (Sandbox Code Playgroud)\n除了这段代码之外,我还需要做些什么吗?根据上述 StackOverflow 答案或 GitHub 页面,我无法判断这段代码是否应该按原样工作,或者是否在幕后进行了其他修改。
\n如果有帮助的话,我正在使用配备 8 核 Intel 处理器的 iMac。我也在 R 中运行它,因为 RStudio 说了一些关于它不支持多核的内容。
\n另请注意,我的问题也广泛涉及这三个过去的问题:
\n\n这是一个拉取请求,意味着代码可以作为分支在 GitHub 上使用,但尚未合并到gganimatemaster 中。
您可以克隆它或复制系统上修改后的包目录。
然后 :
devtools软件包已安装gganimate.Rprojdevtools::load_all(".")并行版本已准备好运行:
anim <- ggplot(mtcars, aes(mpg, disp)) +
transition_states(gear, transition_length = 2, state_length = 1) +
enter_fade() +
exit_fade()
future::plan("sequential") ## default
t0 <- system.time(animate(anim))
print(t0)
# user system total
# 4.384615 1.360656 1.893855
future::plan("multiprocess", workers = 4L)
t1 <- system.time(animate(anim))
# user system total
# 1.30 0.61 3.58
print(t0 / t1)
# user system total
# 4.384615 1.360656 1.893855
Run Code Online (Sandbox Code Playgroud)
为了避免这种情况,load_all您可以打开DESCRIPTION文件并重命名包:
Package: gganimateparallel
Type: Package
Title: A Grammar of Animated Graphics
...
Run Code Online (Sandbox Code Playgroud)
由于小插图似乎很难构建,您可以删除该vignettes目录。
然后RStudio / Build / Install and restart或从包的目录
Rcmd.exe INSTALL --no-multiarch --with-keep.source .
Run Code Online (Sandbox Code Playgroud)
gganimateparallel现在可以作为库在您的系统上使用。
感谢@HenrikBengtsson 所做的令人难以置信的工作future!
| 归档时间: |
|
| 查看次数: |
841 次 |
| 最近记录: |