https://github.com/adabyt/unitconverter
R package for converting temperature, weight, and length units. Final project for CS50R.
https://github.com/adabyt/unitconverter
cs50 cs50r error-handling length-units r r-package rdocumentation temperature-units testthat unit-conversion weight-units
Last synced: 7 months ago
JSON representation
R package for converting temperature, weight, and length units. Final project for CS50R.
- Host: GitHub
- URL: https://github.com/adabyt/unitconverter
- Owner: adabyt
- License: mit
- Created: 2025-06-30T12:30:45.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-06-30T13:24:59.000Z (8 months ago)
- Last Synced: 2025-07-10T08:39:57.497Z (8 months ago)
- Topics: cs50, cs50r, error-handling, length-units, r, r-package, rdocumentation, temperature-units, testthat, unit-conversion, weight-units
- Language: R
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ Unit Converter (CS50R Final Project)
A lightweight R package for converting between common units of temperature, length, and weight. Designed for clarity, ease of use, and reliability โ with unit tests and full documentation.
> ๐งช Final project for [CS50โs Introduction to Programming with R](https://cs50.harvard.edu/r/).
---
## ๐ฆ Functions Provided
| Function | Description | Example |
|----------------|----------------------------------------|----------------|
| `C_to_F()` | Convert Celsius to Fahrenheit | `C_to_F(0)` โ `32 ยฐF` |
| `F_to_C()` | Convert Fahrenheit to Celsius | `F_to_C(32)` โ `0 ยฐC` |
| `kg_to_lbs()` | Convert kilograms to pounds | `kg_to_lbs(1)` โ `2.2 lbs` |
| `lbs_to_kg()` | Convert pounds to kilograms | `lbs_to_kg(2.20462)` โ `1 kg` |
| `cm_to_inches()`| Convert centimetres to inches | `cm_to_inches(2.54)` โ `1 inch` |
| `inches_to_cm()`| Convert inches to centimetres | `inches_to_cm(1)` โ `2.54 cm` |
Each function checks for:
- Missing or null inputs
- Non-numeric inputs
- Precision rounding
---
## ๐งช Testing
Unit tests are provided using the `testthat` framework. Run all tests using:
```r
devtools::test()
```
Test coverage includes:
- Correct conversions
- Handling of NA/missing/null inputs
- Type safety (e.g., strings, lists)
---
## ๐ Project Structure
```
unitconverter/
โโโ R/ # Source functions (e.g., C_to_F.R)
โโโ man/ # Manual .Rd documentation files
โโโ tests/
โ โโโ testthat.R # Load test suite
โ โโโ testthat/ # Unit tests per function
โโโ NAMESPACE # Export definitions
โโโ README.md # This file
```
---
## ๐ How to Use
You can load the functions into your R session as follows:
```r
source("R/C_to_F.R")
C_to_F(25) # Output: 77 ยฐF
```
Or if packaging via devtools:
```r
library(devtools)
load_all("unitconverter")
kg_to_lbs(70)
```
---
## ๐ง Example Output
```r
> C_to_F(100)
[1] "212 ยฐF"
> cm_to_inches(10)
[1] "3.94 inches"
> lbs_to_kg(220)
[1] "99.79 kg"
```
---
## ๐ What I Learned
- How to write modular, reusable R functions
- Robust input validation and error handling
- Documenting with .Rd files
- Testing using testthat
- Building a basic R package structure
---
## ๐ License
MIT
---




