- Visiting a plant is an example of what statistics call an event.
- the outcomes of this event
capture or escaped => sample space is the set of all possible outcomes of an event. - countable sets => discrete sets => can be assigned a positive integer value.
2022-01-18
install library to render Rmarkdown locally
library (markdown)
render("filename") => this will generate a new file
移除工具包:remove.packages("xfun", lib="~/R/win-library/4.0")
取消加载工具包:detach("package:xfun", unload = TRUE)
Rmarkdown 更新了所有的包, 所以如果想要在RStudio里显示实时的slides, 需要添加plugin
点击 RStudio 插件* “Infinite Moon Reader” 在 RStudio 里实时预览幻灯片(每次你保存文档的时候,它会自动重新编译)
“Infinite Moon Reader”插件默认情况下会锁住你的 R 进程,有它没你,有你没它。你可以设置一个选项,让它一边儿凉快去:
options(servr.daemon = TRUE)
你可以把这个设置写在 ~/.Rprofile 文件中,这样你将来所有 R 进程都不会被这个插件挡住去路。
这事情背后的魔法在 servr 包中。
2022-01-19
检查整个session的东西, 用
sessionInfo()
fileshow(csv. file) =>可以直接在excel中,打开CSV文件.
2022-01-23
GIT + Verb +Options (options info. which may be needed for the verb)
windows找出, git所在的路径,在cmd里用 "where git"
查看设定git上关联的github账号在cmd使用指令:
git config --global user.name "###user name"
git config --global user.email "#####******"
不添加""username""情况下,会直接出现已连接的账号.
在git bash里执行的操作如下:
- 改变工作路径: cd ~/Desktop
- 用Git新建一个文件夹: mkdir planets
- 改变现有工作文件夹 cd planets
- 让git创建一个repository仓库,让GIT能够存储你工作的所有版本: Git init
- 用 ls -a 然后你会看见, 创建了一个隐藏的文件夹叫.git
- 一旦删除.git, 就会失去所有的版本历史
- pwd to check 现有的工作文件夹
Nano语句创建简单文本文档
在git bash 里输入
- nano mars.txt
- type in your words,
- ctrl + O, 保存写的文档, enter
4.退出文档 Ctrl + X. - 读取TXT文字, 用 cat mars.txt
- 查看git状态, git status
在git中做commit
- Git status
- git add mars.txt
- git status
- git commit -m "notes message to help you remember later on what we did and why"
做完一个文件的编辑改变后
- git add mars.txt
- git diff 查看发生的变化, 不会看出有任何的变化, 空白输出,因为你还没有commit
- git diff --stage用来查看从你上一次commit,到现在staging area的区别.
- git status,
- git log 查看所有的更改记录
git log -1 =>显示最新的变更数据
git log --oneline =>只显示变更的一条变更,显示一行总结文字 - git show HEAD~0 mars.txt =>会显示从0数到N的commit, 最新的是0, 最初的是N.
取消对一个文档的变化 - 查看状态 git stats
- git checkout HEAD mars.txt
- cat mars.txt 查看回到了之前的状态
- git checkout 81bfi91 恢复到特定某个版本
Happy git with R
clone github 在local
2022-01-24
使用R basis去创建文档,管理project:
- list.files() 可以看见所有子文件夹
- dir.create ("data"") => 创建文件夹
- dir.create ("results"") => 创建文件夹
- list.files(path = "data")
- file.rename("read_matrix.R", "code/read_matirx.R") => rename一个文件,移动位置
- list.files("code")
- file.copy()
- file.remove("readme.md")
- list.files(patterns = "\.dist") => list all files with .dist, back slash
- file.copy(from = dis_files, to = "data")
用R update 更新R不成功,用语句更新
install.packages("installr")
library(installr)
updateR()
- Rstudio中,如何从source, ZIP, link 去安装一个包
- 知道URL, link, with zip
- 安装installr 包,
- 用installr包中的,
install.packages.zip("https://cran.rstudio.com/bin/windows/contrib/4.0/terra_1.4-22.zip")
==解决raster报错的问题==
install.packages('terra', repos='https://rspatial.r-universe.dev')
install.packages('raster', repos='https://rspatial.r-universe.dev')
R read 栅格数据
- library(stars) or library (raster)
- Notice that in the RasterBrick, all of the bands are stored within the actual object. Thus, the RasterBrick object size is much larger than the RasterStack object.
https://www.neonscience.org/resources/learning-hub/tutorials/dc-multiband-rasters-r
The R RasterStack and RasterBrick object types can both store multiple bands. However, how they store each band is different. The bands in a RasterStack are stored as links to raster data that is located somewhere on our computer. A RasterBrick contains all of the objects stored within the actual R object. In most cases, we can work with a RasterBrick in the same way we might work with a RasterStack. However, a RasterBrick is often more efficient and faster to process - which is important when working with larger files.
We can turn a RasterStack into a RasterBrick in R by using brick(StackName). Let's use the object.size() function to compare stack and brick R objects.