Merge branch 'ownNum2Str' into dev
This commit is contained in:
commit
76c6b1ec90
7 changed files with 83 additions and 38 deletions
|
|
@ -3,3 +3,4 @@
|
|||
export(admix1)
|
||||
export(calculatePopLogml)
|
||||
export(learn_simple_partition)
|
||||
export(ownNum2Str)
|
||||
|
|
|
|||
36
R/admix1.R
36
R/admix1.R
|
|
@ -770,39 +770,3 @@ admix1 <- function(tietue) {
|
|||
|
||||
# %--------------------------------------------------------------------------
|
||||
# %-----
|
||||
|
||||
# function str = ownNum2Str(number)
|
||||
|
||||
# absolute = abs(number);
|
||||
|
||||
# if absolute < 1000
|
||||
# str = num2str(number);
|
||||
# elseif absolute < 10000000
|
||||
# first_three = rem(number,1000);
|
||||
# next_four = (number - first_three) /1000;
|
||||
# first_three = abs(first_three);
|
||||
# if first_three<10
|
||||
# first_three = ['00' num2str(first_three)];
|
||||
# elseif first_three<100
|
||||
# first_three = ['0' num2str(first_three)];
|
||||
# else
|
||||
# first_three = num2str(first_three);
|
||||
# end;
|
||||
# str = [num2str(next_four) first_three];
|
||||
# elseif absolute < 100000000
|
||||
# first_four = rem(number,10000);
|
||||
# next_four = (number - first_four) /10000;
|
||||
# first_four = abs(first_four);
|
||||
# if first_four<10
|
||||
# first_four = ['000' num2str(first_four)];
|
||||
# elseif first_four<100
|
||||
# first_four = ['00' num2str(first_four)];
|
||||
# elseif first_four<1000
|
||||
# first_four = ['0' num2str(first_four)];
|
||||
# else
|
||||
# first_four = num2str(first_four);
|
||||
# end;
|
||||
# str = [num2str(next_four) first_four];
|
||||
# else
|
||||
# str = num2str(number);
|
||||
# end;
|
||||
39
R/ownNum2Str.R
Normal file
39
R/ownNum2Str.R
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#' @title Own number to string
|
||||
#' @param number number
|
||||
#' @note On Matlab, if number is NaN the output is 'NaN'. Here, the output will be an error. Also, the function belo expects "number" to have length one, whereas Matlab accepts vectors.
|
||||
#' @export
|
||||
ownNum2Str <- function(number) {
|
||||
absolute <- abs(number)
|
||||
if (absolute < 1000) {
|
||||
str <- as.character(number)
|
||||
} else if (absolute < 10000000) {
|
||||
first_three <- number %% 1000
|
||||
next_four <- (number - first_three) /1000
|
||||
first_three <- abs(first_three)
|
||||
if (first_three < 10) {
|
||||
first_three <- paste0('00', as.character(first_three))
|
||||
} else if (first_three < 100) {
|
||||
first_three <- paste0('0', as.character(first_three))
|
||||
} else {
|
||||
first_three <- as.character(first_three)
|
||||
}
|
||||
str <- paste0(as.character(next_four), first_three)
|
||||
} else if (absolute < 100000000) {
|
||||
first_four <- number %% 10000
|
||||
next_four <- (number - first_four) / 10000
|
||||
first_four <- abs(first_four)
|
||||
if (first_four < 10) {
|
||||
first_four <- paste0('000', as.character(first_four))
|
||||
} else if (first_four < 100) {
|
||||
first_four <- paste0('00', as.character(first_four))
|
||||
} else if (first_four < 1000) {
|
||||
first_four <- paste0('0', as.character(first_four))
|
||||
} else {
|
||||
first_four <- as.character(first_four)
|
||||
}
|
||||
str <- paste0(as.character(next_four), first_four)
|
||||
} else {
|
||||
str <- as.character(number)
|
||||
}
|
||||
return(str)
|
||||
}
|
||||
|
|
@ -9,6 +9,10 @@ rBAPS is currently under development and a stable version is yet to be released.
|
|||
remotes::install_github("ocbe-uio/rBAPS", "dev")
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
rBAPS is Open Software licenced under the [GPL-3](https://tldrlegal.com/license/gnu-general-public-license-v3-(gpl-3)), so all contributions are welcome. You can find a list of todos and pitfalls on the [TODO.md](TODO.md) file.
|
||||
|
||||
## References
|
||||
|
||||
### Scientific papers
|
||||
|
|
|
|||
13
TODO.md
13
TODO.md
|
|
@ -1,3 +1,5 @@
|
|||
# Minimum requirements for next stable release
|
||||
|
||||
For the first stable release of rBAPS, the following features should be implemented:
|
||||
|
||||
- [ ] Clustering of populations (import `greedyPoPMix.m` from BAPS)
|
||||
|
|
@ -7,3 +9,14 @@ For the first stable release of rBAPS, the following features should be implemen
|
|||
- [ ] Admixture analysis (import `admix1.m` from BAPS)
|
||||
|
||||
Note to contributors: as tasks get finished, please update this file with an `x` and keep it there. This should help us fill out a changelog for an eventual stable release.
|
||||
|
||||
# Known pitfalls
|
||||
|
||||
The following behavioral differences have been detected between the Matlab functions and their R counterparts. In order to save time, these differences will not be addressed, since they could require extensive reworking of a function. However, such differences may very well cause unexpected problems in some situations, which is why compiling this list is so important. The list below might provide a good starting point for identifying and fixing bugs:
|
||||
|
||||
## `ownNum2Str`
|
||||
|
||||
Argument | Value | Matlab output | R output
|
||||
---------|-------|---------------|---------
|
||||
`number` | `'NaN` | `'NAN'` | error
|
||||
`number` | `<vector>` | `'<vector elements>'` | `'<vector elements>'` + warning
|
||||
17
man/ownNum2Str.Rd
Normal file
17
man/ownNum2Str.Rd
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/ownNum2Str.R
|
||||
\name{ownNum2Str}
|
||||
\alias{ownNum2Str}
|
||||
\title{Own number to string}
|
||||
\usage{
|
||||
ownNum2Str(number)
|
||||
}
|
||||
\arguments{
|
||||
\item{number}{number}
|
||||
}
|
||||
\description{
|
||||
Own number to string
|
||||
}
|
||||
\note{
|
||||
On Matlab, if number is NaN the output is 'NaN'. Here, the output will be an error. Also, the function belo expects "number" to have length one, whereas Matlab accepts vectors.
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
context("Admixture analysis")
|
||||
|
||||
|
||||
test_that("learn*partition behaves like Matlab", {
|
||||
test_that("learn*partition behaves like on Matlab", {
|
||||
# Test data
|
||||
p1 <- c(0, .5, 1, 1.5)
|
||||
p2 <- c(seq(0, .5, .1), 1, 1, 1, 2)
|
||||
|
|
@ -36,3 +36,10 @@ test_that("learn*partition behaves like Matlab", {
|
|||
expected = matrix(c(1, 2, 2, 2))
|
||||
)
|
||||
})
|
||||
|
||||
test_that("ownNum2Str behaves like on Matlab", {
|
||||
expect_equal(ownNum2Str(1), "1")
|
||||
expect_equal(ownNum2Str(-123456789), "-123456789")
|
||||
expect_equal(ownNum2Str(0), "0")
|
||||
expect_error(ownNum2Str("a"))
|
||||
})
|
||||
Loading…
Add table
Reference in a new issue