Skip to main content

LearnR_Packages

_LearnR_UserGuide_Packages.knit

Packages

GPT-4 explains what an R package is:

“In R and RStudio, a”package” is a collection of functions, data sets, and documentation bundled together. A package provides a way to distribute and share R code and related material with others. They can be thought of as an extension or add-on to the base R system, allowing users to tap into specialized functionality for specific tasks or domains.

The R community has developed thousands of packages, which are available on the Comprehensive R Archive Network (CRAN) and other repositories. These packages cover a vast range of topics and methods, from statistical techniques and data manipulation to graphical display and interactive applications.

In RStudio, you can easily install and manage packages using the “Packages” pane, which provides a user-friendly interface for these tasks. Once a package is installed, you need to use the library() function to load it into your current R session to access its functions and datasets.”


Packages How To

To install a new package:

install.packages("")

To check which packages are installed:

installed.packages()

Darrell’s Most Used Packages (updated periodically)

To install a package:

install.packages()

The packages I’m using most these days:

Data Cleaning and Handling in R

# All Purpose Data
install.packages("tidyverse")

# Data Visualization 
install.packages("ggplot2") # Coursera Preferred Option
install.packages("Plotly")
install.packages("Lattice")
install.packages("RGL")
install.packages("Dygraphs")
install.packages("Leaflet")
install.packages("Highcharter")
install.packages("Patchwork")
install.packages("gganimate")
install.packages("ggridges")


#Database
install.packages("DBI")
install.packages("odbc")
install.packages("RODBC")


#SQL
install.packages("sqldf")

Example Use Case:
  sqldf("SELECT * FROM Orange ORDER BY age ASC, circumference DESC LIMIT 5")

SEE: 
  
  1.3. Importing from SQL Databases
  https://tomaztsql.wordpress.com/2020/04/27/essential-list-of-useful-r-packages-for-data-scientists/

AND:
    SQL in R
    https://dept.stat.lsa.umich.edu/~jerrick/courses/stat701/notes/sql.html

    
    
# HTML
install.packages("shiny")
install.packages("htmltools")



#TBD...

install.packages("")
install.packages("")
install.packages("")
install.packages("")

R & SQL Server Databases - Part 1 Writing R in RStudio, with a SQL Database

GPT-4: If you’re working with SQL Server in R, there are several R packages that can help you connect to, retrieve, and manipulate data. Here are some of the most widely-used ones:

  1. RODBC: This is one of the older and more established packages for ODBC database connections in R. As the name implies, it uses the ODBC (Open Database Connectivity) drivers to establish connections.
    install.packages("RODBC")
-   Usage:
    library(RODBC)
    connection <- odbcConnect("DSN_NAME", uid="YOUR_USER_ID", pwd="YOUR_PASSWORD")
    data <- sqlFetch(connection, "TABLE_NAME")
    close(connection)
  1. DBI and odbc: DBI is a modern database interface for R, and the odbc package, which builds on DBI, provides a way to establish ODBC connections.
    install.packages("DBI")
    install.packages("odbc")
-   Usage:
    library(DBI)
    library(odbc)
    connection <- dbConnect(odbc(), "DSN_NAME", UID="YOUR_USER_ID", PWD="YOUR_PASSWORD")
    data <- dbGetQuery(connection, "SELECT * FROM TABLE_NAME")
    dbDisconnect(connection)
  1. RSQLServer: This package is a DBI-compliant interface specifically for SQL Server. It might be more intuitive if you’re exclusively working with SQL Server.
    # Using devtools to install from GitHub
    devtools::install_github('imanbio/RSQLServer')
  • Usage:
    library(RSQLServer)
    connection <- dbConnect(RSQLServer::SQLServer(), url="jdbc:sqlserver://SERVER_NAME;databaseName=DB_NAME", user="YOUR_USER_ID", password="YOUR_PASSWORD")
    data <- dbGetQuery(connection, "SELECT * FROM TABLE_NAME")
    dbDisconnect(connection)
  1. pool: This is an auxiliary package that can be used in combination with the others. It allows you to manage and optimize your database connections using connection pooling, which can be particularly helpful when building Shiny apps that connect to databases.
    install.packages("pool")

When selecting a package, consider the specific features you need, as well as any dependencies. For example, RODBC might require configuration of an ODBC Data Source Name (DSN), while RSQLServer uses JDBC. In general, the DBI and odbc combination is widely adopted and offers a good mix of features and ease of use.

### R & SQL Server Databases - Part 2 Writing SQL in RStudio
#### See Images paired with these instructions:
Connections Native Server Database
Connections R Console
Connections Opens in Console Editor
Console Editor results can be seen below editor

HTML in RStudio

GPT-4 on RStudio tools for HTML:

Shiny: It’s an R package that allows for the creation of interactive web apps. While it primarily uses its own system of UI components, you can integrate raw HTML and CSS if needed.

R Markdown with HTML Output: When you create an R Markdown document in RStudio, you can knit the document to produce an HTML output. Within the R Markdown document, you can mix Markdown, R code, and even raw HTML.

htmltools: This R package provides functions and tools for working with HTML. It can be particularly useful when you want to generate dynamic HTML content based on data analysis in R.

install.packages("shiny")

install.packages("htmltools")

END

END for Now…

# UNDER CONSTRUCTION………….

### Title
### Title
TEXT
r install.packages("")
END

Title

TEXT

install.packages("")

END

### Title
### Title
TEXT
r install.packages("")
END

Title

TEXT

install.packages("")

END

Popular posts from this blog

I can't find my Blogger.com DNS record?! Here's how to find it. It took me a long time because Google's own instructions fail.

I use Blogger.com for my websites. I find it easier to use without having to know a lot of technical things.  However, I bought my domain names from a third-party website, and I host them on Blogger.com.  After years of this, I tried a hosted Word Press site, I found the GUI awful and editor even worse. I'm sure it has amazing features and it looked pretty, but it was absolutely useless to me as a writer. So... I went back to Blogger.com, but ran into an odd issue. I needed my personal DNS record to provide to my domain provider.  The Google instructions " Set up a custom domain " say that I should get a pop-up message with my DNS records. There is noplace in the blogger interface to find the DNS record that I can find, neither in the website or elsewhere. That is an odd user interface failure. Others expressed the same issue and even ChatGPT4o Pro couldn't help, it kept taking me back to these instructions.  Finally! I found the answer on this page: Why I'm not g...

Learning Coding Fundamentals with Python and SQL

Learning Coding Fundamentals with Python and SQL Learning Coding Fundamentals with Python and SQL Darrell Wolfe ————————————————————— Disclaimers First It is not my intention to steal anyone’s thunder or copyrighted material. I do not believe these seven fundamentals are specific to Dr Hill (below), who was the initial inspiration to start this note file. That beings said, she has a particularly unique method of teaching, and I strongly recommend that if you are someone who needs a good teacher, she’s the one! This is my own process of learning. I take information from as many sources and teachers as possible, synthesis that material, and then practice it until I get good at it. Further, I like to take detailed notes so I can refer back to them when a particular tool starts getting rusty or dusty in my brain after disuse for a time. When I learned .rmd through my Google Data Analytics Certification, I...

Are gas prices affected by the sitting US President (Under Construction, testing html view)

Gas Prices in USA, historical analysis This report is intended to review gas prices in the USA historically for comparison against various claims. One such claim is that the sitting US President has a direct affect on gas prices. Data from the EIA - US Energy Information Administration This dataframe set GasPrices_eia_prices_1970_2022 comes from the EIA website as a downloadable CSV. The EIA provides an FAQ for using the data, which includes instructions to download the CSV and for a reference Excel document that helps with conversion. “To obtain the historical prices from the SEDS data, use the CSV file for All States—Prices. In the file, the code for gasoline prices for the transportation sector, in $/MMBtu , is: State Abbreviation (in column A) and MGACD (in column B). For example, the code for Alaska is AK—MGACD . Those prices, in $/MMBtu, can be converted to approximate dollars per gallon using the heat contents in Table A3 Petroleum consumption and fuel eth...