Skip to content

Commit

Permalink
version 0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
phamdn authored and cran-robot committed Sep 23, 2020
1 parent 90fc2fb commit 1febb9e
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 26 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: centrifugeR
Type: Package
Title: Non-Trivial Balance of Centrifuge Rotors
Version: 0.1.4
Version: 0.1.5
Authors@R: person("Duy Nghia", "Pham", email = "[email protected]",
role = c("aut", "cre"), comment = c(ORCID = "0000-0003-1349-1710"))
Description: Find the numbers of tubes that can be loaded in centrifuge
Expand All @@ -13,10 +13,10 @@ Depends: R (>= 3.6.0)
Imports: pracma (>= 2.2.9), grDevices, graphics, utils
License: GPL-3
Encoding: UTF-8
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
NeedsCompilation: no
Packaged: 2020-04-16 22:56:00 UTC; Nghia Pham
Packaged: 2020-09-23 07:20:57 UTC; Nghia Pham
Author: Duy Nghia Pham [aut, cre] (<https://orcid.org/0000-0003-1349-1710>)
Maintainer: Duy Nghia Pham <[email protected]>
Repository: CRAN
Date/Publication: 2020-04-17 08:00:06 UTC
Date/Publication: 2020-09-23 08:40:15 UTC
20 changes: 11 additions & 9 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
d95115a83321f291c39f334c4745e400 *DESCRIPTION
2feddedc1ccfe37fd6556794d484296f *NAMESPACE
43db61f120dd6e76f18997a40171887d *R/centrifugeR-package.R
ce853759f392760689d2046c6fb19fee *DESCRIPTION
3af5fc3e6dfc5a06dbecb9f558084db0 *NAMESPACE
fec74a6f6c2a159bd88f13136c33a65f *R/centrifugeR-package.R
7b45d554c097f85b3ab182bd9557310e *R/rotorCheck.R
65344e484e1ddbadb470d6a7d372a720 *R/rotorEqual.R
cb42bcfdefd64e9b905c85320a9e6ed2 *R/rotorEqual.R
c71d809258dea030959fcbeb08a7c591 *R/rotorSpeed.R
4b6d974ac8b36bdf1798a86722f880a3 *R/rotorUnequal.R
ac17fdef594c928cd753a572361bfa41 *R/zzz.R
b6791096e96ffc85ae1f7b0dfdcf0f2c *R/rotorUnequal.R
b9d5239b9c40116638086c4a78b75061 *R/rotorVerify.R
72a264431206dd046d6f506f24e6f0c2 *R/zzz.R
75abefbea9db81229f4d1aa8773fd523 *inst/CITATION
c6c0ecfb0bb0f56c77c9908b83c1fb12 *man/centrifugeR-package.Rd
e4ea5155ffa8a8932a1e9f4b86f24e2e *man/centrifugeR-package.Rd
bb9e60d3dc45ecf2bbe9c09854ffdd96 *man/rotorCheck.Rd
15d13414f51d8fc370379d2f3349cb38 *man/rotorEqual.Rd
a33e22e27cef5d84c49b0f0b2ec657d8 *man/rotorEqual.Rd
8c2bd025acf39a5c77376017773b2b69 *man/rotorSpeed.Rd
7611e56bbdda41710997d276775ee8fc *man/rotorUnequal.Rd
6b6bfbf5bd36611daf26344b569387a6 *man/rotorUnequal.Rd
aa5a66e9cc172b129994243da008388e *man/rotorVerify.Rd
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(rotorCheck)
export(rotorEqual)
export(rotorSpeed)
export(rotorUnequal)
export(rotorVerify)
importFrom(grDevices,palette)
importFrom(grDevices,rainbow)
importFrom(graphics,pie)
Expand Down
5 changes: 3 additions & 2 deletions R/centrifugeR-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' Find the numbers of tubes that can be loaded in centrifuge rotors in a single
#' operation and show how to balance these tubes in cases of equal or unequal
#' masses. Refer to Pham (2020) <doi:10.31224/osf.io/4xs38> for more information
#' masses. Refer to Pham (2020) \url{https://doi.org/10.31224/osf.io/4xs38} for more information
#' on package functionality.
#'
#' @author Duy Nghia Pham \email{nghiapham@@yandex.com}
Expand All @@ -17,10 +17,11 @@
#' balance these tubes given that they have the same mass. If their masses are
#' not the same, use \code{\link{rotorUnequal}} to know which tubes must be
#' increased in mass before they can be loaded. Also, call
#' \code{\link{rotorVerify}} to verify pre-existing tube configurations and
#' \code{\link{rotorSpeed}} if RPM/RCF conversion is needed.
#'
#' @section Copyright: centrifugeR: Non-Trivial Balance of Centrifuge Rotors.
#' Copyright (C) 2019 Duy Nghia Pham \cr \cr centrifugeR is free software:
#' Copyright (C) 2020 Duy Nghia Pham \cr \cr centrifugeR is free software:
#' you can redistribute it and/or modify it under the terms of the GNU General
#' Public License as published by the Free Software Foundation, either version
#' 3 of the License, or (at your option) any later version. \cr \cr
Expand Down
6 changes: 5 additions & 1 deletion R/rotorEqual.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#'
#' @param n an integer, the number of rotor buckets.
#' @param k an integer, the number of tubes.
#' @param seed an integer, the seed for random number generation. Setting a seed
#' ensures the reproducibility of the result. See \code{\link{set.seed}} for
#' more details.
#'
#' @details The number of rotor buckets \code{n} ranges from \code{4} to
#' \code{48}. The number of tubes \code{k} must be greater than \code{0} and
Expand All @@ -29,7 +32,8 @@
#' rotorEqual(30, 19)
#'
#' @export
rotorEqual <- function (n, k) {
rotorEqual <- function (n, k, seed = 2019) {
set.seed(seed)
if (n < 4 | n > 48) {
stop("The rotor must have at least 4 buckets and no more than 48 buckets. \n")
}
Expand Down
14 changes: 9 additions & 5 deletions R/rotorUnequal.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#' @param n an integer, the number of rotor buckets.
#' @param mass a numeric vector with optional \code{names} attribute, the masses
#' (and optional names) of tubes.
#' @param seed an integer, the seed for random number generation. Setting a seed
#' ensures the reproducibility of the result. See \code{\link{set.seed}} for
#' more details.
#'
#' @details The number of rotor buckets \code{n} ranges from \code{4} to
#' \code{48}. The number of tubes (i.e. \code{length(mass)}) should not be
Expand Down Expand Up @@ -48,7 +51,8 @@
#' rotorUnequal(30, small.samples)
#'
#' @export
rotorUnequal <- function (n, mass = NULL) {
rotorUnequal <- function (n, mass = NULL, seed = 2019) {
set.seed(seed)
if (n < 4 | n > 48) {
stop("The rotor must have at least 4 buckets and no more than 48 buckets. \n")
}
Expand All @@ -57,9 +61,6 @@ rotorUnequal <- function (n, mass = NULL) {
input <- scan("", list(character(), numeric()))
mass <- "names<-"(input[[2]], input[[1]])
}
if (sum(mass <= 0) > 0) {
warning("Mass values should be positive. \n")
}
if (is.null(names(mass))) {
nm <- vector()
for (i in seq(length(mass))) {
Expand All @@ -69,7 +70,10 @@ rotorUnequal <- function (n, mass = NULL) {
}
k <- length(mass)
if (k == 0 | k > n) {
stop("The number of tubes must not be 0 or greater than the number of rotor buckets. \n")
stop("The number of tubes must neither be 0 nor greater than the number of rotor buckets. \n")
}
if (sum(mass <= 0) > 0) {
stop("Mass values must be positive. \n")
}
prime <- unique(factors(n))
coeff <- mapply(seq, 0, n / prime, SIMPLIFY = FALSE)
Expand Down
55 changes: 55 additions & 0 deletions R/rotorVerify.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#' Verify Centrifuge Balance
#'
#' \code{rotorVerify} checks whether the rotor is balanced given the positions
#' of tubes of equal mass.
#'
#' @param n an integer, the number of rotor buckets.
#' @param pos an integer vector, the positions of tubes.
#'
#' @details The number of rotor buckets \code{n} ranges from \code{4} to
#' \code{48}. The positions of tubes \code{pos} ranges from 1 to \code{n}.
#'
#' @return \code{rotorVerify} returns \code{1} if the rotor is balanced and
#' \code{0} if the rotor is unbalanced.
#'
#' @references Johnsson M. Balancing a centrifuge. R-bloggers. 2016. Available
#' from: \url{https://www.r-bloggers.com/2016/06/balancing-a-centrifuge/}.
#'
#' @seealso \code{\link{rotorCheck}} for checking centrifuge rotors.
#'
#' @examples
#' rotorVerify(30, c(10, 20, 30))
#' rotorVerify(30, c(1, 11, 21, 4, 28))
#'
#' @export
rotorVerify <- function (n, pos) {
if (n < 4 | n > 48) {
stop("The rotor must have at least 4 buckets and no more than 48 buckets. \n")
}
k <- length(pos)
if (k == 0 | k > n) {
stop("The number of tubes must neither be 0 nor greater than the number of rotor buckets. \n")
}
if (sum(pos < 1 | pos > n | pos != floor(pos) | duplicated(pos)) > 0) {
stop("The positions of tubes must be different integers ranging from 1 to n. \n")
}
prime <- unique(factors(n))
coeff <- mapply(seq, 0, n / prime, SIMPLIFY = FALSE)
coeff.com <- do.call(expand.grid, coeff)
linear <- apply(coeff.com, 1, function(x) dot(x, prime))
if (!k %in% linear | !(n - k) %in% linear) {
stop(paste("CANNOT load", k, "tubes in a rotor with", n, "buckets. \n"))
}
p2c <- function(x){
theta <- (x - 1) * 2 * pi / n
c(cos(theta), sin(theta))
}
if (sum(abs(rowSums(sapply(pos, p2c))) < 10^-10) == 2) {
message("The rotor is balanced")
result <- 1
} else {
message("The rotor is unbalanced")
result <- 0
}
result
}
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.onAttach <- function(libname, pkgname) {
packageStartupMessage("centrifugeR Copyright (C) 2019 Duy Nghia Pham")
packageStartupMessage("centrifugeR Copyright (C) 2020 Duy Nghia Pham")
packageStartupMessage("centrifugeR is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions.")
}
5 changes: 3 additions & 2 deletions man/centrifugeR-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/rotorEqual.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/rotorUnequal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions man/rotorVerify.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1febb9e

Please sign in to comment.