R 基础学习笔记 from 2022-01-16

  1. Visiting a plant is an example of what statistics call an event.
  2. the outcomes of this event
    capture or escaped => sample space is the set of all possible outcomes of an event.
  3. 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里执行的操作如下:

  1. 改变工作路径: cd ~/Desktop
  2. 用Git新建一个文件夹: mkdir planets
  3. 改变现有工作文件夹 cd planets
  4. 让git创建一个repository仓库,让GIT能够存储你工作的所有版本: Git init
  5. 用 ls -a 然后你会看见, 创建了一个隐藏的文件夹叫.git
  6. 一旦删除.git, 就会失去所有的版本历史
  7. pwd to check 现有的工作文件夹

Nano语句创建简单文本文档

在git bash 里输入

  1. nano mars.txt
  2. type in your words,
  3. ctrl + O, 保存写的文档, enter
    4.退出文档 Ctrl + X.
  4. 读取TXT文字, 用 cat mars.txt
  5. 查看git状态, git status

在git中做commit

  1. Git status
  2. git add mars.txt
  3. git status
  4. git commit -m "notes message to help you remember later on what we did and why"

做完一个文件的编辑改变后

  1. git add mars.txt
  2. git diff 查看发生的变化, 不会看出有任何的变化, 空白输出,因为你还没有commit
  3. git diff --stage用来查看从你上一次commit,到现在staging area的区别.
  4. git status,
  5. git log 查看所有的更改记录
    git log -1 =>显示最新的变更数据
    git log --oneline =>只显示变更的一条变更,显示一行总结文字
  6. git show HEAD~0 mars.txt =>会显示从0数到N的commit, 最新的是0, 最初的是N.
    取消对一个文档的变化
  7. 查看状态 git stats
  8. git checkout HEAD mars.txt
  9. cat mars.txt 查看回到了之前的状态
  10. git checkout 81bfi91 恢复到特定某个版本

Happy git with R
clone github 在local

2022-01-24

使用R basis去创建文档,管理project:

  1. list.files() 可以看见所有子文件夹
  2. dir.create ("data"") => 创建文件夹
  3. dir.create ("results"") => 创建文件夹
  4. list.files(path = "data")
  5. file.rename("read_matrix.R", "code/read_matirx.R") => rename一个文件,移动位置
  6. list.files("code")
  7. file.copy()
  8. file.remove("readme.md")
  9. list.files(patterns = "\.dist") => list all files with .dist, back slash
  10. file.copy(from = dis_files, to = "data")

用R update 更新R不成功,用语句更新

install.packages("installr")
library(installr)
updateR()

  • Rstudio中,如何从source, ZIP, link 去安装一个包
  1. 知道URL, link, with zip
  2. 安装installr 包,
  3. 用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 栅格数据

  1. library(stars) or library (raster)
  2. 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.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 数据的导入 参考文章 在R语言中,常常用到导入数据的源文件是Excel文件,CSV文件,文本文件等等。 导入csv...
    天涯清水阅读 33,466评论 0 13
  • 2. Git 基础 写在前面:这一部分内容真的是好多好多好多ε(┬┬﹏┬┬)3,不过也是使用 Git 最有用的啦,...
    sylvia_yue阅读 2,607评论 0 2
  • Git基础 获取Git仓库的两种方式 将尚未进行版本控制的本地目录转换为Git仓库 从其他服务器==克隆==一个已...
    squarejohn_5dc8阅读 2,669评论 0 1
  • [TOC] Git 内部实现原理剖析[https://www.jianshu.com/p/8154ac47d406...
    Whyn阅读 3,980评论 0 0
  • 一、Git简介 用一句话来说: Git是目前世界上最先进的分布式版本控制系统(没有之一) Git有什么特点:简单的...
    天痕丶阅读 1,592评论 0 0