From 6c72c0f69ee2d55d49fe804fb58adafd937a3a7a Mon Sep 17 00:00:00 2001 From: "taha@asks2" Date: Mon, 10 Jul 2023 04:29:19 +0200 Subject: [PATCH] Added functions to convert arcminutes and arcseconds <-> degrees Very simple stuff. Would have been nice if there was an easy way to get arcminutes and arcseconds notation to/from degrees, but that's a whole other can of worms. No such R packages exist as far as I can tell. Where are all the astronomy peeps? --- DESCRIPTION | 2 +- NAMESPACE | 4 ++++ R/numeric.R | 58 ++++++++++++++++++++++++++++++++++++++++++++- README.md | 2 +- man/amin2degrees.Rd | 20 ++++++++++++++++ man/asec2degrees.Rd | 20 ++++++++++++++++ man/degrees2amin.Rd | 17 +++++++++++++ man/degrees2asec.Rd | 17 +++++++++++++ man/trapz.Rd | 2 +- 9 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 man/amin2degrees.Rd create mode 100644 man/asec2degrees.Rd create mode 100644 man/degrees2amin.Rd create mode 100644 man/degrees2asec.Rd diff --git a/DESCRIPTION b/DESCRIPTION index d753216..5d97ed0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: common Type: Package Title: A collection of solarchemist's common R functions -Version: 0.1.1 +Version: 0.1.2 Description: A package containing solarchemist's commonly-used R functions and scripts. Authors@R: person("Taha", "Ahmed", email = "taha@chepec.se", role = c("aut", "cre")) License: GPL-3 + file LICENSE diff --git a/NAMESPACE b/NAMESPACE index 4e97d06..fcf649b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,8 +10,12 @@ export(ProvideSampleId) export(SubfigureGenerator) export(SubstrateHistory) export(TabularXtableHeader) +export(amin2degrees) export(as.degrees) export(as.radians) +export(asec2degrees) +export(degrees2amin) +export(degrees2asec) export(int2padstr) export(is.wholenumber) export(molarity2mass) diff --git a/R/numeric.R b/R/numeric.R index 3e073bd..5667c31 100644 --- a/R/numeric.R +++ b/R/numeric.R @@ -1,6 +1,62 @@ +#' Convert arcminutes to degrees +#' +#' Convert arcminutes to degrees +#' +#' @param x arcminutes, numeric +#' +#' @seealso https://en.wikipedia.org/w/index.php?title=Minute_and_second_of_arc&oldid=1159601591 +#' +#' @return degrees, numeric +#' @export +amin2degrees <- function(x) { + return (x / 60) +} + + +#' Convert arcseconds to degrees +#' +#' Convert arcseconds to degrees +#' +#' @param x arcseconds, numeric +#' +#' @seealso https://en.wikipedia.org/w/index.php?title=Minute_and_second_of_arc&oldid=1159601591 +#' +#' @return degrees, numeric +#' @export +asec2degrees <- function(x) { + return (common::amin2degrees(x / 60)) +} + + +#' Convert degrees to arcminutes +#' +#' Convert degrees to arcminutes +#' +#' @param x degrees, numeric +#' +#' @return arcminutes, numeric +#' @export +degrees2amin <- function(x) { + return (60 * x) +} + + +#' Convert degrees to arcseconds +#' +#' Convert degrees to arcseconds +#' +#' @param x degrees, numeric +#' +#' @return arcseconds, numeric +#' @export +degrees2asec <- function(x) { + return (60 * common::degrees2amin(x)) +} + + #' Calculate area under a curve #' -#' Numerically calculate area under an arbitrary curve (defined by x, y coord pairs) +#' Numerically calculate area under an arbitrary curve (defined by x, y coord pairs) #' using trapezodial integration. See Wikipedia for more info on trapz integration. #' #' @param x vector (of length n) diff --git a/README.md b/README.md index 9c7adc6..a048cf9 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ I suggest the following package rebuild procedure: + Run `devtools::check()`. Should complete with no warnings, errors or notes: ``` -── R CMD check results ─────────────────────────────────────── common 0.1.1 ──── +── R CMD check results ─────────────────────────────────────── common 0.1.2 ──── Duration: 8.1s 0 errors ✔ | 0 warnings ✔ | 0 notes ✔ diff --git a/man/amin2degrees.Rd b/man/amin2degrees.Rd new file mode 100644 index 0000000..2047b5a --- /dev/null +++ b/man/amin2degrees.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/numeric.R +\name{amin2degrees} +\alias{amin2degrees} +\title{Convert arcminutes to degrees} +\usage{ +amin2degrees(x) +} +\arguments{ +\item{x}{arcminutes, numeric} +} +\value{ +degrees, numeric +} +\description{ +Convert arcminutes to degrees +} +\seealso{ +https://en.wikipedia.org/w/index.php?title=Minute_and_second_of_arc&oldid=1159601591 +} diff --git a/man/asec2degrees.Rd b/man/asec2degrees.Rd new file mode 100644 index 0000000..bf6f9ba --- /dev/null +++ b/man/asec2degrees.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/numeric.R +\name{asec2degrees} +\alias{asec2degrees} +\title{Convert arcseconds to degrees} +\usage{ +asec2degrees(x) +} +\arguments{ +\item{x}{arcseconds, numeric} +} +\value{ +degrees, numeric +} +\description{ +Convert arcseconds to degrees +} +\seealso{ +https://en.wikipedia.org/w/index.php?title=Minute_and_second_of_arc&oldid=1159601591 +} diff --git a/man/degrees2amin.Rd b/man/degrees2amin.Rd new file mode 100644 index 0000000..86975e4 --- /dev/null +++ b/man/degrees2amin.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/numeric.R +\name{degrees2amin} +\alias{degrees2amin} +\title{Convert degrees to arcminutes} +\usage{ +degrees2amin(x) +} +\arguments{ +\item{x}{degrees, numeric} +} +\value{ +arcminutes, numeric +} +\description{ +Convert degrees to arcminutes +} diff --git a/man/degrees2asec.Rd b/man/degrees2asec.Rd new file mode 100644 index 0000000..c6bb572 --- /dev/null +++ b/man/degrees2asec.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/numeric.R +\name{degrees2asec} +\alias{degrees2asec} +\title{Convert degrees to arcseconds} +\usage{ +degrees2asec(x) +} +\arguments{ +\item{x}{degrees, numeric} +} +\value{ +arcseconds, numeric +} +\description{ +Convert degrees to arcseconds +} diff --git a/man/trapz.Rd b/man/trapz.Rd index c4f2b62..da679ec 100644 --- a/man/trapz.Rd +++ b/man/trapz.Rd @@ -15,6 +15,6 @@ trapz(x, y) vector (of length n - 1) } \description{ -Numerically calculate area under an arbitrary curve (defined by x, y coord pairs) +Numerically calculate area under an arbitrary curve (defined by x, y coord pairs) using trapezodial integration. See Wikipedia for more info on trapz integration. }