.chapter3<-function(i=0){ " i Chapter 3: Introduction to R packages i Explanation - ------------------------------------- -- -------------------------------------- 1 What is an R package? 21 R program to get all R packages 2 Advantages of using R packages 22 3 How to find a list of all R packages 23 4 Finding the manual for a specific package 5 Loaded vs. preinstalled packages 6 Load and unload an R package 7 Find out all loaded R packages 8 Find out all preinstalled R packages 9 Find out all preinstalled R packages 10 Method I to install an R package 11 Method II to install an R package 12 Method III to install an R package 13 A var has all installed R packages 14 Is an R package loaded? 15 Is an R package installed already? 16 Package description 17 Functions include in a package 18 Most useful R commands related R packages 19 Videos 20 Links Example #1:>.c3 # see the above list Example #2:>.c3(1) # see the first explanation ";.zchapter3(i)} .n3chapter<-23 .zchapter3<-function(i){ if(i==0){ print(.c3) }else{ .printEachQ(3,i,.n3chapter) } } .c3<-.chapter3 .C3EXPLAIN1<-"What is an R package? //////////////////////////////// R packages are written by a group of people or individual who usually have expertise around a specific area to serve a specific purpose. /////////////////////////////// " .C3EXPLAIN2<-"Advantages of using R packages //////////////////////////////// 1) You don t have to reinvent wheel 2) Powerful 3) Many useful functions 4) Many finance-related R packages available 5) Save time 6) Download others programs and extend them /////////////////////////////// " .C3EXPLAIN3<-"How to find a list of all R packages //////////////////////////////// Step 1: go to https://www.r-project.org/ Step 2: Click CRAN under download https://cran.r-project.org/mirrors.html Step 3: Choose a mirror server Step 4: click 'packages' on the left-hand side Step 5: you will find two lists Table of available packages, sorted by date of publication Table of available packages, sorted by name [any one will be fine] /////////////////////////////// " .C3EXPLAIN4<-"Finding the manual for a specific package //////////////////////////////// For example, to find the pdf manual for fImport, we have the following steps Step 1: http://www.r-project.org/ Step 2: click 'CRAN' Step 3: choose a 'mirror' Step 4: click 'packages' on the left-hand Step 5: using Ctrl-f to search 'fImport' Step 6: download the pdf manual /////////////////////////////// " .C3EXPLAIN5<-"loaded vs. preinstalled packages //////////////////////////////// A loaded R package: you can use it A preinstalled R package is the condition that you could load it /////////////////////////////// " .C3EXPLAIN5<-"loaded vs. preinstalled packages //////////////////////////////// A loaded R package: you can use it A preinstalled R package is the condition that you could load it /////////////////////////////// " .C3EXPLAIN6<-"Load and unload an R package //////////////////////////////// There are several ways to load an R package. 1) library(fImport) 2) require(fImport) 3) click 'Packages...' on the menu bar then 'load package...' To unload an R package ------------------------- We use detach() function detach(package:XML) /////////////////////////////// " .C3EXPLAIN7<-"To find out all loaded R packages //////////////////////////////// > search() [1] \".GlobalEnv\" \"package:stats\" \"package:graphics\" [4] \"package:grDevices\" \"package:datasets\" \"package:utils\" [7] \"package:methods\" \"Autoloads\" \"package:base\" /////////////////////////////// " .C3EXPLAIN8<-"Find out all preinstalled R packages //////////////////////////////// > library() Packages in library C:/Users/yany/Documents/R/win-library/3.3 : animation A Gallery of Animations in Statistics and Utilities to Create Animations assertthat Easy pre and post assertions. base64enc Tools for base64 encoding BB Solving and Optimizing Large-Scale Nonlinear Systems (more ....) /////////////////////////////// " .C3EXPLAIN9<-"Find out all preinstalled R packages ( a list) //////////////////////////////// > library() Packages in library C:/Users/yany/Documents/R/win-library/3.3 : animation A Gallery of Animations in Statistics and Utilities to Create Animations assertthat Easy pre and post assertions. base64enc Tools for base64 encoding BB Solving and Optimizing Large-Scale Nonlinear Systems BH Boost C++ Header Files bindr Parametrized Active Bindings bindrcpp An 'Rcpp' Interface to Active Bindings bitops Bitwise Operations BLCOP Black-Litterman and Copula Opinion Pooling Frameworks cairoDevice Embeddable Cairo Graphics Device Driver colorspace Color Space Manipulation cowplot Streamlined Plot Theme and Plot Annotations for 'ggplot2' cubature Adaptive Multivariate Integration over Hypercubes curl A Modern and Flexible Web Client for R data.table Extension of `data.frame` DBI R Database Interface deldir Delaunay Triangulation and Dirichlet (Voronoi) Tessellation DEoptimR Differential Evolution Optimization in Pure R dfoptim Derivative-Free Optimization dichromat Color Schemes for Dichromats digest Create Compact Hash Digests of R Objects dplyr A Grammar of Data Manipulation ecodist Dissimilarity-based functions for ecological analysis energy E-Statistics: Multivariate Inference via the Energy of Data evaluate Parsing and Evaluation Tools that Provide More Details than the Default excel.link Convenient Data Exchange with Microsoft Excel fAssets Rmetrics - Analysing and Modelling Financial Assets fBasics Rmetrics - Markets and Basic Statistics fCopulae Rmetrics - Bivariate Dependence Structures with Copulae fMultivar Rmetrics - Analysing and Modeling Multivariate Financial Return Distributions fOptions Rmetrics - Pricing and Evaluating Basic Options foreach Provides Foreach Looping Construct for R fPortfolio Rmetrics - Portfolio Selection and Optimization ggforce Accelerating 'ggplot2' ggplot2 Create Elegant Data Visualisations Using the Grammar of Graphics ggpubr 'ggplot2' Based Publication Ready Plots ggrepel Repulsive Text and Label Geoms for 'ggplot2' ggsci Scientific Journal and Sci-Fi Themed Color Palettes for 'ggplot2' ggsignif Significance Brackets for 'ggplot2' glue Interpreted String Literals gridExtra Miscellaneous Functions for \"Grid\" Graphics gss General Smoothing Splines gtable Arrange 'Grobs' in Tables hexbin Hexagonal Binning Routines highr Syntax Highlighting for R Source Code htmltools Tools for HTML htmlwidgets HTML Widgets for R httpuv HTTP and WebSocket Server Library httr Tools for Working with URLs and HTTP IBrokers R API to Interactive Brokers Trader Workstation iterators Provides Iterator Construct for R jsonlite A Robust, High Performance JSON Parser and Generator for R kernlab Kernel-Based Machine Learning Lab knitr A General-Purpose Package for Dynamic Report Generation in R labeling Axis Labeling lazyeval Lazy (Non-Standard) Evaluation magrittr A Forward-Pipe Operator for R markdown 'Markdown' Rendering for R mime Map Filenames to MIME Types minqa Derivative-free optimization algorithms by quadratic approximation mnormt The Multivariate Normal and t Distributions munsell Utilities for Using Munsell Colours mvnormtest Normality test for multivariate variables mvtnorm Multivariate Normal and t Distributions NLP Natural Language Processing Infrastructure numDeriv Accurate Numerical Derivatives openssl Toolkit for Encryption, Signatures and Certificates Based on OpenSSL optextras Tools to Support Optimization Possibly with Bounds and Masks optimx A Replacement and Extension of the optim() Function PerformanceAnalytics Econometric tools for performance and risk analysis pkgconfig Private Configuration for 'R' Packages plogr The 'plog' C++ Logging Library plotly Create Interactive Web Graphics via 'plotly.js' plyr Tools for Splitting, Applying and Combining Data png Read and write PNG images PortfolioAnalytics Portfolio Analysis, Including Numerical Methods for Optimization of Portfolios purrr Functional Programming Tools qrcode QRcode Generator for R quadprog Functions to solve Quadratic Programming Problems. quantmod Quantitative Financial Modelling Framework R.methodsS3 S3 Methods Simplified R.oo R Object-Oriented Programming with or without References R.utils Various Programming Utilities R6 Classes with Reference Semantics rattle Graphical User Interface for Data Science in R Rcgmin Conjugate Gradient Minimization of Nonlinear Functions RColorBrewer ColorBrewer Palettes Rcpp Seamless R and C++ Integration RCurl General Network (HTTP/FTP/...) Client Interface for R reshape2 Flexibly Reshape Data: A Reboot of the Reshape Package rgl 3D Visualization Using OpenGL Rglpk R/GNU Linear Programming Kit Interface RGtk2 R bindings for Gtk 2.8.0 and above RGtk2Extras Data frame editor and dialog making wrapper for RGtk2 rJava Low-Level R to Java Interface rlang Functions for Base Types and Core R and 'Tidyverse' Features rneos XML-RPC Interface to NEOS robustbase Basic Robust Statistics rpart.plot Plot 'rpart' Models: An Enhanced Version of 'plot.rpart' Rsolnp General Non-Linear Optimization Rsymphony SYMPHONY in R RUnit R Unit Test Framework Rvmmin Variable Metric Nonlinear Function Minimization scales Scale Functions for Visualization setRNG Set (Normal) Random Number Generator and Seed shiny Web Application Framework for R slam Sparse Lightweight Arrays and Matrices sn The Skew-Normal and Related Distributions, such as the Skew-t sourcetools Tools for Reading, Tokenizing and Parsing R Code stabledist Stable Distribution Functions stringi Character String Processing Facilities stringr Simple, Consistent Wrappers for Common String Operations svUnit SciViews GUI API - Unit testing tibble Simple Data Frames tidyr Easily Tidy Data with 'spread()' and 'gather()' Functions timeDate Rmetrics - Chronological and Calendar Objects timeSeries Rmetrics - Financial Time Series Objects tm Text Mining Package truncnorm Truncated normal distribution TTR Technical Trading Rules tweenr Interpolate Data for Smooth Animations ucminf General-Purpose Unconstrained Non-Linear Optimization udunits2 Udunits-2 Bindings for R units Measurement Units for R Vectors viridisLite Default Color Maps from 'matplotlib' (Lite Version) wordcloud Word Clouds WriteXLS Cross-Platform Perl Based R Function to Create Excel 2003 (XLS) and Excel 2007 (XLSX) Files XLConnect Excel Connector for R XLConnectJars JAR Dependencies for the XLConnect Package XML Tools for Parsing and Generating XML Within R and S-Plus xtable Export Tables to LaTeX or HTML xts eXtensible Time Series yaml Methods to Convert R Data to YAML and Back zoo S3 Infrastructure for Regular and Irregular Time Series (Z's Ordered Observations) Packages in library C:/Program Files/R/R-3.3.3/library : base The R Base Package boot Bootstrap Functions (Originally by Angelo Canty for S) class Functions for Classification cluster \"Finding Groups in Data\": Cluster Analysis Extended Rousseeuw et al. codetools Code Analysis Tools for R compiler The R Compiler Package datasets The R Datasets Package foreign Read Data Stored by Minitab, S, SAS, SPSS, Stata, Systat, Weka, dBase, ... graphics The R Graphics Package grDevices The R Graphics Devices and Support for Colours and Fonts grid The Grid Graphics Package KernSmooth Functions for Kernel Smoothing Supporting Wand & Jones (1995) /////////////////////////////// " .C3EXPLAIN10<-"Method I: install R package //////////////////////////////// We use command of install.packages(\"packageName\") >install.packages(\"fImport\") Installing package into C:/Users/yany/Documents/R/win-library/3.3 (as lib is unspecified) --- Please select a CRAN mirror for use in this session --- [choose a mirror location] --- Please select a CRAN mirror for use in this session --- trying URL 'https://mirrors.nics.utk.edu/cran/bin/windows/contrib/3.3/fImport_3000.82.zip' Content type 'application/zip' length 442192 bytes (431 KB) downloaded 431 KB package fImport successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\\Users\\yany\\AppData\\Local\\Temp\\RtmpSi40vh\\downloaded_packages Type library(fImport) to see > library(fImport) Loading required package: timeDate Loading required package: timeSeries /////////////////////////////// " .C3EXPLAIN11<-"Method II: install R package //////////////////////////////// Click \"Packages\" on the menu bar Click \"Install Package(s) ... Choose a mirror location chose your package from a list /////////////////////////////// " .C3EXPLAIN12<-"Method III: install R package //////////////////////////////// Step 1: manually download an R pakcage Step 2: Click \"Packages\" on the menu bar Click \"Install Package(s) from local files... Step 3: find the saved package and install /////////////////////////////// " .C3EXPLAIN13<-"A var has all installed R packages //////////////////////////////// > x<-.packages(all.available=T) > length(x) [1] 164 > head(x) [1] \"animation\" \"assertthat\" \"base64enc\" \"BB\" \"BH\" [6] \"bindr\" /////////////////////////////// " .C3EXPLAIN14<-"Is an R package loaded? //////////////////////////////// we use \"package:PackageName\" %in% search Below, we use the R package called XML as an example > \"package:XML\" %in% search() [1] FALSE /////////////////////////////// " .C3EXPLAIN15<-"Is an R package preinstalled? //////////////////////////////// we use command of \"packageName\" %in% .packages(all.available=T) For example, \"XML\" %in% .packages(all.available=T) [1] TRUE /////////////////////////////// " .C3EXPLAIN16<-"PackageDescription() function //////////////////////////////// > packageDescription(\"fImport\") Package: fImport Version: 3000.82 Revision: 5455 Date: 2013-03-15 Title: Rmetrics - Economic and Financial Data Import Author: Diethelm Wuertz and many others Depends: R (>= 2.13.0), methods, timeDate, timeSeries Suggests: RUnit Maintainer: Yohan Chalabi Description: Environment for teaching \"Financial Engineering and Computational Finance\" Note: Several parts are still preliminary and may be changed in the future. this typically includes function and argument names, as well as defaults for arguments and return values. LazyData: yes License: GPL (>= 2) URL: http://www.rmetrics.org Packaged: 2013-03-15 12:46:58 UTC; yankee NeedsCompilation: no Repository: CRAN Date/Publication: 2013-03-15 14:54:11 Built: R 3.3.3; ; 2017-11-08 18:42:38 UTC; windows -- File: C:/Users/yany/Documents/R/win-library/3.3/fImport/Meta/package.rds /////////////////////////////// " .C3EXPLAIN17<-"functions include in a pakcage //////////////////////////////// > help(package=\"XML\") starting httpd help server ... done http://127.0.0.1:17234/library/XML/html/00Index.html Tools for Parsing and Generating XML Within R and S-Plus [R logo] Documentation for package 'XM' version 3.98-1.6 DESCRIPTION file. Help Pages A C D E F G H I L M N O P R S T U X misc -- A -- addAttributes Add child nodes to an XML node addAttributes-method Add child nodes to an XML node addChildren Add child nodes to an XML node addChildren-method Add child nodes to an XML node addNode Add a node to a tree addNode.XMLHashTree Add a node to a tree addSibling Manipulate sibling XML nodes append.XMLNode Add children to an XML node append.xmlNode Add children to an XML node asXMLNode Converts non-XML node objects to XMLTextNode objects asXMLTreeNode Convert a regular XML node to one for use in a \"flat\" tree -- C -- catalogAdd Manipulate XML catalog contents catalogClearTable Manipulate XML catalog contents catalogDump Manipulate XML catalog contents catalogLoad Manipulate XML catalog contents catalogResolve Look up an element via the XML catalog mechanism coerce-method Constructor for DTD reference coerce-method Simple classes for identifying an XML document containing R code coerce-method Class to represent reference to C-level data structure for an XML document coerce-method Classes to describe an XML node object. coerce-method Converts non-XML node objects to XMLTextNode objects coerce-method Transform between XML representations coerce-method Create internal XML node or document object coerce-method Parse a URI string into its elements coerce-method Read data from one or more HTML tables coerce-method Output internal XML Tree coerce-method Classes for working with XML Schema coerce-method Get definitions of any namespaces defined in this XML node coerce-method Find a namespace definition object by searching ancestor nodes coerce-method Extract or set the contents of a leaf XML node comment.SAX Generic Methods for SAX callbacks comment.SAX-method Generic Methods for SAX callbacks COMPACT Parse an XML document with options controlling the parser. compareXMLDocs Indicate differences between two XML documents [more...] /////////////////////////////// " .C3EXPLAIN18<-"Most useful R commands related R packages //////////////////////////////// Description R command ---------------------------- ----------- Find out all loaded packages >search() load an R package > library(XML) > require(XML) Unload a package > detach(package:XML) Is XML loaded ? > \"package:XML\" %in% search() Find out all preinstalled packages >library() >.packages(all.available=T) Find out whether a specific package is preinstalled > library(XML) > \"XML\" %in% .packages(all.available=T) Get info on about a package > help(package=\"timeDate\") > library(help=\"timeDate\") > packageDescription(\"timeDate\") /////////////////////////////// " .C3EXPLAIN19<-"Videos //////////////////////////////// R Programming||Connecting google spreadsheet with R - R Programming (t9:33) https://www.youtube.com/watch?v=7l2_R61jrUU RichardOnData,2021, 20 R Packages You Should Know (t30:41) https://www.youtube.com/watch?v=npOf6aXdguY Stat Course,2022, R packages: installing, loading, using and updating R packages (t16:08) https://www.youtube.com/watch?v=2nfWaMsD1fw weecology,2021, Introduction to R Packages (t4:48) https://www.youtube.com/watch?v=NAArCsmztOI (advanced materials) Muschelli, John, 2019, R Package Development 1: Where to Start https://www.youtube.com/watch?v=79s3z0gIuFU&list=PLk3B5c8iCV-T4LM0mwEyWIunIunLyEjqM /////////////////////////////// " .C3EXPLAIN20<-"Links //////////////////////////////// Home page for R http://r-project.org R Packages: A Beginner's Guide https://www.datacamp.com/community/tutorials/r-packages-guide Introduction to R packages http://r-pkgs.had.co.nz/intro.html Introduction to R packages http://faculty.washington.edu/kenrice/rintro/sess08.pdf Slides: introduction to R packages https://www.slideshare.net/RsquaredIn/r-programming-managing-r-packages Introduction to R and packages http://pebesma.staff.ifgi.de/Aufbaukurs/R/slides_R.pdf /////////////////////////////// " .C3EXPLAIN21<-"Program to get all R packages //////////////////////////////// loc<-\"http://cran.us.r-project.org\" x<-available.packages(repos =loc) df<-data.frame(x) dim(df) # [1] 20287 17 colnames(df) [1] \"Package\" \"Version\" \"Priority\" [4] \"Depends\" \"Imports\" \"LinkingTo\" [7] \"Suggests\" \"Enhances\" \"License\" [10] \"License_is_FOSS\" \"License_restricts_use\" \"OS_type\" [13] \"Archs\" \"MD5sum\" \"NeedsCompilation\" [16] \"File\" \"Repository\" head(df,2) Package Version Priority Depends Imports LinkingTo A3 A3 1.0.0 R (>= 2.15.0), xtable, pbapply AalenJohansen AalenJohansen 1.0 Suggests Enhances License License_is_FOSS License_restricts_use A3 randomForest, e1071 GPL (>= 2) AalenJohansen knitr, rmarkdown GPL (>= 2) OS_type Archs MD5sum NeedsCompilation File A3 027ebdd8affce8f0effaecfcd5f5ade2 no AalenJohansen d7eb2a6275daa6af43bf8a980398b312 no Repository A3 http://cran.us.r-project.org/src/contrib AalenJohansen http://cran.us.r-project.org/src/contrib /////////////////////////////// "