Never spend time to decorate this report!
cat() or print() if the
function doesn’t showround() or signif()to show appropriate
decimal point.
You can organize them clearly using this section: optional
# libraries('librarian') # smart install & loading a pkg: shelf() unshelf()
# library(devtools) # pkg development, install_github()
# library(dplyr) # data wrangling, %>%
# library(tidyverse) # data wrangling set:'dplyr', 'ggplot2' etc
# Rafalib pkgs
# library('downloader') # for download
# library('dagdata') # for 3 mice data
# libraries('dslabs') # for murders, gene expression,
# libraries('rafalib') # for mypar, maplot, popsd, popvar, sboxplot, shist, splot, ssplit
## Q1. Install the following packages.
# 'librarian', 'devtools', 'tidyverse' for general functions.
# 'downloader', 'dagdata' for DAL book specific functions
if (!"librarian" %in% installed.packages()) install.packages("librarian");
if (!"devtools" %in% installed.packages()) install.packages("devtools");
if (!"tidyverse" %in% installed.packages()) install.packages("tidyverse");
if (!"downloader" %in% installed.packages()) install.packages("downloader");
if (!"dagdata" %in% installed.packages()) install.packages("dagdata");
if (!"rafalib" %in% installed.packages()) install.packages("rafalib");
if (!"dslabs" %in% installed.packages()) install.packages("dslabs");
## Q2. Load, detach, unload "downloader".
## show sessionInfo() in each step
sessionInfo()
## R version 4.4.1 (2024-06-14 ucrt)
## Platform: x86_64-w64-mingw32/x64
## Running under: Windows 10 x64 (build 19045)
##
## Matrix products: default
##
##
## locale:
## [1] LC_COLLATE=Korean_Korea.utf8 LC_CTYPE=Korean_Korea.utf8
## [3] LC_MONETARY=Korean_Korea.utf8 LC_NUMERIC=C
## [5] LC_TIME=Korean_Korea.utf8
##
## time zone: Asia/Seoul
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## loaded via a namespace (and not attached):
## [1] digest_0.6.37 R6_2.5.1 fastmap_1.2.0 xfun_0.47
## [5] cachem_1.1.0 knitr_1.48 htmltools_0.5.8.1 rmarkdown_2.28
## [9] lifecycle_1.0.4 cli_3.6.3 sass_0.4.9 jquerylib_0.1.4
## [13] compiler_4.4.1 rstudioapi_0.16.0 tools_4.4.1 evaluate_0.24.0
## [17] bslib_0.8.0 yaml_2.3.10 rlang_1.1.4 jsonlite_1.8.8
library(downloader)
sessionInfo()
## R version 4.4.1 (2024-06-14 ucrt)
## Platform: x86_64-w64-mingw32/x64
## Running under: Windows 10 x64 (build 19045)
##
## Matrix products: default
##
##
## locale:
## [1] LC_COLLATE=Korean_Korea.utf8 LC_CTYPE=Korean_Korea.utf8
## [3] LC_MONETARY=Korean_Korea.utf8 LC_NUMERIC=C
## [5] LC_TIME=Korean_Korea.utf8
##
## time zone: Asia/Seoul
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] downloader_0.4
##
## loaded via a namespace (and not attached):
## [1] digest_0.6.37 R6_2.5.1 fastmap_1.2.0 xfun_0.47
## [5] cachem_1.1.0 knitr_1.48 htmltools_0.5.8.1 rmarkdown_2.28
## [9] lifecycle_1.0.4 cli_3.6.3 sass_0.4.9 jquerylib_0.1.4
## [13] compiler_4.4.1 rstudioapi_0.16.0 tools_4.4.1 evaluate_0.24.0
## [17] bslib_0.8.0 yaml_2.3.10 rlang_1.1.4 jsonlite_1.8.8
detach('package:downloader')
sessionInfo()
## R version 4.4.1 (2024-06-14 ucrt)
## Platform: x86_64-w64-mingw32/x64
## Running under: Windows 10 x64 (build 19045)
##
## Matrix products: default
##
##
## locale:
## [1] LC_COLLATE=Korean_Korea.utf8 LC_CTYPE=Korean_Korea.utf8
## [3] LC_MONETARY=Korean_Korea.utf8 LC_NUMERIC=C
## [5] LC_TIME=Korean_Korea.utf8
##
## time zone: Asia/Seoul
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## loaded via a namespace (and not attached):
## [1] digest_0.6.37 R6_2.5.1 fastmap_1.2.0 xfun_0.47
## [5] cachem_1.1.0 knitr_1.48 htmltools_0.5.8.1 rmarkdown_2.28
## [9] lifecycle_1.0.4 cli_3.6.3 downloader_0.4 sass_0.4.9
## [13] jquerylib_0.1.4 compiler_4.4.1 rstudioapi_0.16.0 tools_4.4.1
## [17] evaluate_0.24.0 bslib_0.8.0 yaml_2.3.10 rlang_1.1.4
## [21] jsonlite_1.8.8
library(downloader)
detach('package:downloader', unload=T)
sessionInfo()
## R version 4.4.1 (2024-06-14 ucrt)
## Platform: x86_64-w64-mingw32/x64
## Running under: Windows 10 x64 (build 19045)
##
## Matrix products: default
##
##
## locale:
## [1] LC_COLLATE=Korean_Korea.utf8 LC_CTYPE=Korean_Korea.utf8
## [3] LC_MONETARY=Korean_Korea.utf8 LC_NUMERIC=C
## [5] LC_TIME=Korean_Korea.utf8
##
## time zone: Asia/Seoul
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## loaded via a namespace (and not attached):
## [1] digest_0.6.37 R6_2.5.1 fastmap_1.2.0 xfun_0.47
## [5] cachem_1.1.0 knitr_1.48 htmltools_0.5.8.1 rmarkdown_2.28
## [9] lifecycle_1.0.4 cli_3.6.3 sass_0.4.9 jquerylib_0.1.4
## [13] compiler_4.4.1 rstudioapi_0.16.0 tools_4.4.1 evaluate_0.24.0
## [17] bslib_0.8.0 yaml_2.3.10 rlang_1.1.4 jsonlite_1.8.8
downloaderis attached on .Globalenv, digest is
loaded via a namespace additionally.downloaderis detatched, downloader moves to the
namespace & digest remain on their namespace.# Q3. Download "femaleMiceWeights.csv" inside the "genomicsclass/dagdata" on GitHub
librarian::shelf(downloader)
##
## The 'cran_repo' argument in shelf() was not set, so it will use
## cran_repo = 'https://cran.r-project.org' by default.
##
## To avoid this message, set the 'cran_repo' argument to a CRAN
## mirror URL (see https://cran.r-project.org/mirrors.html) or set
## 'quiet = TRUE'.
## 1) Check or set your working directory
getwd();
## [1] "C:/Users/yejin/BiS335"
## 2) Find the options of download() in "downloader" pkg
# by using ?, help(), & args()
?download
## httpd 도움말 서버를 시작합니다 ...
## 완료
?downloader::download
args(downloader::download)
## function (url, ...)
## NULL
## 3) Check apropos("download")
apropos("^download")
## [1] "download" "download.file" "download.packages"
#### Get help for download.file
?download.file
args(download.file)
## function (url, destfile, method, quiet = FALSE, mode = "w", cacheOK = TRUE,
## extra = getOption("download.file.extra"), headers = NULL,
## ...)
## NULL
## 4) Download the file with the following arguments:
# download(url, destfile=file1);
url <- "https://raw.githubusercontent.com/genomicsclass/dagdata/master/inst/extdata/femaleMiceWeights.csv"
file1 <- "femaleMiceWeights_github.csv" # filename to be saved
## 5) Check if the file is in your working directory
# using list.files() & file.exists()
# before & after download the file.
list.files()
## [1] "HW1-1.1-v24.Rmd"
file.exists(file1)
## [1] FALSE
download(url , destfile=file1)
list.files()
## [1] "femaleMiceWeights_github.csv" "HW1-1.1-v24.Rmd"
file.exists(file1)
## [1] TRUE
# Q4. Install 'dagdata' pkg from GitHub at "genomicsclass/dagdata"
## You need "devtools" pkg to use install_github()
if(!require(dagdata)) {install_github("genomicsclass/dagdata") }
## 필요한 패키지를 로딩중입니다: dagdata
# More efficiently use shelf & unshelf instead of library & detach
librarian::shelf(genomicsclass/dagdata);
##
## The 'cran_repo' argument in shelf() was not set, so it will use
## cran_repo = 'https://cran.r-project.org' by default.
##
## To avoid this message, set the 'cran_repo' argument to a CRAN
## mirror URL (see https://cran.r-project.org/mirrors.html) or set
## 'quiet = TRUE'.
# Q5. Find the Path of the file
(dag_dir <- system.file(package="dagdata"))
## [1] "C:/Users/sypark/AppData/Local/R/win-library/4.4/dagdata"
list.files(file.path(dag_dir))
## [1] "data" "DESCRIPTION" "extdata" "help" "html"
## [6] "Meta" "NAMESPACE" "script"
list.files(file.path(dag_dir, "extdata"))
## [1] "admissions.csv" "astronomicalunit.csv"
## [3] "babies.txt" "femaleControlsPopulation.csv"
## [5] "femaleMiceWeights.csv" "mice_pheno.csv"
## [7] "msleep_ggplot2.csv" "README"
## [9] "spider_wolff_gorb_2013.csv"
# Q6. Assign the "full path & file name" to file2
(file2 <- system.file(package="dagdata", "extdata", "femaleMiceWeights.csv"))
## [1] "C:/Users/sypark/AppData/Local/R/win-library/4.4/dagdata/extdata/femaleMiceWeights.csv"
# Q7. Load file1 and file2
(dat1 <- read.csv(file1))
(dat2 <- read.csv(file2))
## Different ways
dat1<- read.csv(url);
dat2 <- read.csv(system.file(package = 'dagdata', 'extdata', 'femaleMiceWeights.csv'))
# Q8. Compare them using View() & identical().
View(dat1)
View(dat2)
identical(dat1, dat2)
## [1] TRUE
## Set the data name to "dat" after you confirm the identity
dat <- dat1