# 继续学R：安装软件包

in r •  6 months ago

(图片从 @dapeng 的帖子里偷的）

# 运行脚本

`R --slave -f hello.R`

`Rscript`

`Rscript hello.R`

`Rscript -e "1+1"`
`Rscript -e 'print("Hello World");'`
`Rscript -e "print(\"Hello World\");"`
`Rscript -e "print(\"Hello World\");1+1;2+2"`

# 安装软件包

`install.packages("example_package")`

`install.packages("caTools")`

Would you like to use a personal library instead? (y/n) y

`library(caTools)`

# 见识一下

``````#install.packages("caTools")  # install external package
library(caTools)             # external package providing write.gif function
jet.colors <- colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F",
"yellow", "#FF7F00", "red", "#7F0000"))
dx <- 400                    # define width
dy <- 400                    # define height
C  <- complex(real = rep(seq(-2.2, 1.0, length.out = dx), each = dy),
imag = rep(seq(-1.2, 1.2, length.out = dy), dx))
C <- matrix(C, dy, dx)       # reshape as square matrix of complex numbers
Z <- 0                       # initialize Z to zero
X <- array(0, c(dy, dx, 20)) # initialize output 3D array
for (k in 1:20) {            # loop with 20 iterations
Z <- Z^2 + C               # the central difference equation
X[, , k] <- exp(-abs(Z))   # capture results
}
write.gif(X, "Mandelbrot.gif", col = jet.colors, delay = 25)
``````

# 相关链接

Sort Order:

·

btw，现在刷steemit有种感觉被两个老师监督念书的赶脚(´▽｀)

@dancingapple O哥親自教授

·

·
·

o哥这个例子跟你帖子里拍那张书页里的“康威生命游戏”是类似的

·
·
·

·
·

·
·
·

o 哥可否授权允许把这两篇帖子(以及后续)转载到 《学 R》一书的主页 http://xuer.pzhao.net

·

·
·

still "hello world" again, but i will try to follow this until end :)