In this post, I will record some common R’s packages and functions.
- drake_plan(): create a workflow data frame
- make(): build your project
- vis_drake_graph(): show an interactive visual network representation of your workflow
- drake_history(): show what you built, when you built in, and the function arguments you used
- loadd(): load one or more built targets into your R session
- readd(): read and return a built target
- outdated(): see which targets will be built in the next make()
- deps(): check the dependencies of a command or function
- failed(): list the targets that failed to build in the last make()
- diagnose(): return the full context of a build, including errors, warnings, and messages
- comment style
Use GET() function to connect with website and get data from it.
2.1 never use these two commands in the head of R script
- first (instead use here::here())
rm(list = ls())
Don’t try to change the .Rprofile and affect the data
2.2 check the loaded packages
2.3 set the working directory
I custom the shortcuting in R with *Cmd+Shift+H*.
2.4 tidy code’s formatation
Here I just introduce the tidy method in RStudio.
- select the region, e.g. *Cmd + A*
- print shortcuting *Cmd + Shift + A* to format the code or run *style active file* in addin
2.5 get file’s path
full_path <- normalizePath(file_eg) dir_name<-dirname() file_name<-basename()
2.6 insert and run R chunck in Rmarkdown
insert: *Cmd+Opt+i* run: *Cmd+Shift+enter*
3 Run R Code
library("ggplot2") ggplot(mpg) + geom_point(aes(x = displ, y = hwy, colour = cty, size = cty))