Skip to content

Commit

Permalink
worked on package website
Browse files Browse the repository at this point in the history
  • Loading branch information
gbganalyst committed Feb 22, 2024
1 parent 6eaf956 commit ce253e9
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 836 deletions.
32 changes: 15 additions & 17 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
# What is New in *bulkreadr*?

## bulkreadr 1.1.0 (2023-11-13)
# bulkreadr 1.1.0 (2023-11-13)

This update includes the following new features:

- `generate_dictionary()`: This function is designed to automatically create a comprehensive data dictionary from labelled datasets. The generated dictionary provides detailed insights into each variable, aiding in better data understanding and management.
* `generate_dictionary()`: This function is designed to automatically create a comprehensive data dictionary from labelled datasets. The generated dictionary provides detailed insights into each variable, aiding in better data understanding and management.

- `look_for()`: This enhances the capability to efficiently search within labelled datasets. It allows users to quickly find variable names and their descriptions by searching for specific keywords. This feature streamlines data exploration and analysis, particularly in large datasets with extensive variables.
* `look_for()`: This enhances the capability to efficiently search within labelled datasets. It allows users to quickly find variable names and their descriptions by searching for specific keywords. This feature streamlines data exploration and analysis, particularly in large datasets with extensive variables.

These enhancements aim to improve the user experience in data management and exploration within `bulkreadr`. We hope these new features will assist our users in more effectively navigating and understanding their labelled datasets.

## bulkreadr 1.0.0 (2023-09-20)
# bulkreadr 1.0.0 (2023-09-20)

This update includes the following new features and improvements:

- Developed `read_stata_data()` to import Stata data file (`.dta`) into an R data frame, converting labeled variables into factors.
* Developed `read_stata_data()` to import Stata data file (`.dta`) into an R data frame, converting labeled variables into factors.

- Reduced dependency packages to optimize efficiency.
* Reduced dependency packages to optimize efficiency.


## 0.2.0 (2023-09-11)
# 0.2.0 (2023-09-11)

This update includes the following new features and improvements:

- Developed bulkreadr vignette
* Developed bulkreadr vignette

- Developed `read_spss_data()` to seamlessly import data from an SPSS data (`.sav` or `.zsav`) files and converting labelled variables into factors, a crucial step that enhances the ease of data manipulation and analysis within the R programming environment.
* Developed `read_spss_data()` to seamlessly import data from an SPSS data (`.sav` or `.zsav`) files and converting labelled variables into factors, a crucial step that enhances the ease of data manipulation and analysis within the R programming environment.

- Added more unit tests
* Added more unit tests

## 0.1.0 (2023-07-24)
# 0.1.0 (2023-07-24)

This update includes the following new features and improvements:

- Improved error handling by adding meaningful error messages for all functions within `bulkreadr` package. This will make it easier for users to identify and troubleshoot issues that may arise during their use of the package.
* Improved error handling by adding meaningful error messages for all functions within `bulkreadr` package. This will make it easier for users to identify and troubleshoot issues that may arise during their use of the package.

- Added package-level documentation. The user can now use `?bulkreadr::bulkreadr` for basic package-level documentation.
* Added package-level documentation. The user can now use `?bulkreadr::bulkreadr` for basic package-level documentation.

- Added `inspect_na()` to summarize missingness in data frame columns and `fill_missing_values()` to impute missing values in a dataframe.
* Added `inspect_na()` to summarize missingness in data frame columns and `fill_missing_values()` to impute missing values in a dataframe.

## 0.0.0.9 (2023-07-03)
# 0.0.0.9 (2023-07-03)

The development version of bulkreadr is now on Githhub.

301 changes: 1 addition & 300 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ options(tibble.print_min = 5, tibble.print_max = 5)
<!-- badges: start -->
[![R-CMD-check](https://github.com/gbganalyst/bulkreadr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/gbganalyst/bulkreadr/actions/workflows/R-CMD-check.yaml)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/bulkreadr)](https://cran.r-project.org/package=bulkreadr)
[![metacran downloads](https://cranlogs.r-pkg.org/badges/bulkreadr)](https://cran.r-project.org/package=bulkreadr)
[![metacran downloads](https://cranlogs.r-pkg.org/badges/grand-total/bulkreadr)](https://cran.r-project.org/package=bulkreadr)
[![Codecov test coverage](https://codecov.io/gh/gbganalyst/bulkreadr/branch/main/graph/badge.svg)](https://app.codecov.io/gh/gbganalyst/bulkreadr?branch=main)
<!-- badges: end -->
Expand Down Expand Up @@ -75,306 +76,6 @@ library(dplyr)
```


## Functions in bulkreadr package

This section provides a concise overview of the different functions available in the `bulkreadr` package. These functions serve various purposes and are designed to handle importing of data in bulk.

| Functions to Import Data | Other Functions |
|--------------------------------------|-----------------------------------------|
| [`read_excel_workbook()`](#read_excel_workbook) | [`generate_dictionary()`](#generate_dictionary) |
| [`read_excel_files_from_dir()`](#read_csv_files_from_dir) | [`look_for()`](#look_for) |
| [`read_csv_files_from_dir()`](#read_csv_files_from_dir) | [`pull_out()`](#pull_out) |
| [`read_gsheets()`](#read_gsheets) | [`convert_to_date()`](#convert_to_date) |
| [`read_spss_data()`](#read_spss_data) | [`inspect_na()`](#inspect_na) |
| [`read_stata_data()`](#read_stata_data) | [`fill_missing_values()`](#fill_missing_values) |


**Note:**

> For the majority of functions within this package, we will utilize data stored in the system file by the `bulkreadr`, which can be accessed using the `system.file()` function. If you wish to utilize your own data stored in your local directory, please ensure that you have set the appropriate file path prior to using any functions provided by the bulkreadr package.

## `read_excel_workbook()`

`read_excel_workbook()` reads all the data from the sheets of an Excel workbook and return an appended dataframe.

```{r example1}
# path to the xls/xlsx file.
path <- system.file("extdata", "Diamonds.xlsx", package = "bulkreadr", mustWork = TRUE)
# read the sheets
read_excel_workbook(path = path)
```

## `read_excel_files_from_dir()`

`read_excel_files_from_dir()` reads all Excel workbooks in the `"~/data"` directory and returns an appended dataframe.

```{r example1a}
# path to the directory containing the xls/xlsx files.
directory <- system.file("xlsxfolder", package = "bulkreadr")
# import the workbooks
read_excel_files_from_dir(dir_path = directory)
```

## `read_csv_files_from_dir()`

`read_csv_files_from_dir()` reads all csv files from the `"~/data"` directory and returns an appended dataframe. The resulting dataframe will be in the same order as the CSV files in the directory.

```{r example2}
# path to the directory containing the CSV files.
directory <- system.file("csvfolder", package = "bulkreadr")
# import the csv files
read_csv_files_from_dir(dir_path = directory)
```

## `read_gsheets()`

The `read_gsheets()` function imports data from multiple sheets in a Google Sheets spreadsheet and appends the resulting dataframes from each sheet together to create a single dataframe. This function is a powerful tool for data analysis, as it allows you to easily combine data from multiple sheets into a single dataset.

```{r, include=FALSE}
googlesheets4::gs4_deauth()
```

```{r example3}
# Google Sheet ID or the link to the sheet
sheet_id <- "1izO0mHu3L9AMySQUXGDn9GPs1n-VwGFSEoAKGhqVQh0"
# read all the sheets
read_gsheets(ss = sheet_id)
```

## `read_spss_data()`

`read_spss_data()` is designed to seamlessly import data from an SPSS data (`.sav` or `.zsav`) files. It converts labelled variables into factors, a crucial step that enhances the ease of data manipulation and analysis within the R programming environment.

```{r spssdata1}
# Read an SPSS data file without converting variable labels as column names
file_path <- system.file("extdata", "Wages.sav", package = "bulkreadr")
data <- read_spss_data(file = file_path)
data
```

```{r spssdata2}
# Read an SPSS data file and convert variable labels as column names
data <- read_spss_data(file = file_path, label = TRUE)
data
```

## read_stata_data()

`read_stata_data()` reads Stata data file (`.dta`) into an R data frame, converting labeled variables into factors.

**Read the Stata data file without converting variable labels as column names**

```{r statadata1}
file_path <- system.file("extdata", "Wages.dta", package = "bulkreadr")
data <- read_stata_data(file = file_path)
data
```

**Read the Stata data file and convert variable labels as column names**

```{r statadata2}
data <- read_stata_data(file = file_path, label = TRUE)
data
```


## `generate_dictionary()`

`generate_dictionary()` creates a data dictionary from a specified data frame. This function is particularly useful for understanding and documenting the structure of your dataset, similar to data dictionaries in Stata or SPSS.

```{r}
# Creating a data dictionary from an SPSS file
file_path <- system.file("extdata", "Wages.sav", package = "bulkreadr")
wage_data <- read_spss_data(file = file_path)
generate_dictionary(wage_data)
```


## `look_for()`

The `look_for()` function is designed to emulate the functionality of the Stata `lookfor` command in R. It provides a powerful tool for searching through large datasets, specifically targeting variable names, variable label descriptions, factor levels, and value labels. This function is handy for users working with extensive and complex datasets, enabling them to quickly and efficiently locate the variables of interest.


```{r}
# Look for a single keyword.
look_for(wage_data, "south")
```


## `pull_out()`

`pull_out()` is similar to `[`. It acts on vectors, matrices, arrays and lists to extract or replace parts. It is pleasant to use with the magrittr (`⁠%>%`⁠) and base(`|>`) operators.

```{r example4}
top_10_richest_nig <- c("Aliko Dangote", "Mike Adenuga", "Femi Otedola", "Arthur Eze", "Abdulsamad Rabiu", "Cletus Ibeto", "Orji Uzor Kalu", "ABC Orjiakor", "Jimoh Ibrahim", "Tony Elumelu")
top_10_richest_nig %>%
pull_out(c(1, 5, 2))
```

```{r}
top_10_richest_nig %>%
pull_out(-c(1, 5, 2))
```


## `convert_to_date()`

`convert_to_date()` parses an input vector into POSIXct date-time object. It is also powerful to convert from excel date number like `42370` into date value like `2016-01-01`.

```{r example 5}
## ** heterogeneous dates **
dates <- c(
44869, "22.09.2022", NA, "02/27/92", "01-19-2022",
"13-01- 2022", "2023", "2023-2", 41750.2, 41751.99,
"11 07 2023", "2023-4"
)
# Convert to POSIXct or Date object
convert_to_date(dates)
# It can also convert date time object to date object
convert_to_date(lubridate::now())
```


```{r example5}
# With dataframe
file_path <- system.file("extdata", "OGD.xlsx", package = "bulkreadr")
ogd_data <- read_excel_workbook(path = file_path)
ogd_data %>% head()
# Convert to POSIXct or Date object
modified_ogd_data <- ogd_data %>%
mutate(Date_format = convert_to_date(Date))
modified_ogd_data %>% head()
```


## `inspect_na()`

`inspect_na()` summarizes the rate of missingness in each column of a data frame. For a grouped data frame, the rate of missingness is summarized separately for each group.

```{r example 6a}
# dataframe summary
inspect_na(airquality)
# grouped dataframe summary
airquality %>%
group_by(Month) %>%
inspect_na()
```

## `fill_missing_values()`

`fill_missing_values()` in an efficient function that addresses missing values in a dataframe. It uses imputation by function, meaning it replaces missing data in numeric variables with either the mean or the median, and in non-numeric variables with the mode. The function takes a column-based imputation approach, ensuring that replacement values are derived from the respective columns, resulting in accurate and consistent data. This method enhances the integrity of the dataset and promotes sound decision-making and analysis in data processing workflows.

```{r example 6}
df <- tibble::tibble(
Sepal_Length = c(5.2, 5, 5.7, NA, 6.2, 6.7, 5.5),
Sepal.Width = c(4.1, 3.6, 3, 3, 2.9, 2.5, 2.4),
Petal_Length = c(1.5, 1.4, 4.2, 1.4, NA, 5.8, 3.7),
Petal_Width = c(NA, 0.2, 1.2, 0.2, 1.3, 1.8, NA),
Species = c("setosa", NA, "versicolor", "setosa",
NA, "virginica", "setosa"
)
)
df
# Using mean to fill missing values for numeric variables
result_df_mean <- fill_missing_values(df, use_mean = TRUE)
result_df_mean
# Using median to fill missing values for numeric variables
result_df_median <- fill_missing_values(df, use_mean = FALSE)
result_df_median
```

### Impute missing values (NAs) in a grouped data frame

You can use the `fill_missing_values()` in a grouped data frame by using other grouping and map functions. Here is an example of how to do this:

```{r}
sample_iris <- tibble::tibble(
Sepal_Length = c(5.2, 5, 5.7, NA, 6.2, 6.7, 5.5),
Petal_Length = c(1.5, 1.4, 4.2, 1.4, NA, 5.8, 3.7),
Petal_Width = c(0.3, 0.2, 1.2, 0.2, 1.3, 1.8, NA),
Species = c("setosa", "setosa", "versicolor", "setosa",
"virginica", "virginica", "setosa")
)
sample_iris
sample_iris %>%
group_by(Species) %>%
group_split() %>%
map_df(fill_missing_values)
```

## Context

bulkreadr draws on and complements / emulates other packages such as readxl, readr, and googlesheets4 to read bulk data in R.
Expand Down
Loading

0 comments on commit ce253e9

Please sign in to comment.