mirror of
				https://github.com/msberends/AMR.git
				synced 2025-11-04 12:45:31 +01:00 
			
		
		
		
	few extra tests
This commit is contained in:
		
							
								
								
									
										5
									
								
								NEWS.md
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								NEWS.md
									
									
									
									
									
								
							@@ -26,6 +26,7 @@
 | 
			
		||||
    ```r
 | 
			
		||||
    my_list = list(age = septic_patients$age, sex = septic_patients$sex)
 | 
			
		||||
    my_list %>% freq(age)
 | 
			
		||||
    my_list %>% freq(sex)
 | 
			
		||||
    ```
 | 
			
		||||
    
 | 
			
		||||
#### Other
 | 
			
		||||
@@ -53,8 +54,8 @@
 | 
			
		||||
  * New Lancefield classification for *Streptococcus* to categorise them into Lancefield groups
 | 
			
		||||
* For convience, new descriptive statistical functions `kurtosis` and `skewness` that are lacking in base R - they are generic functions and have support for vectors, data.frames and matrices
 | 
			
		||||
* Function `g.test` to perform the Χ<sup>2</sup> distributed [*G*-test](https://en.wikipedia.org/wiki/G-test), which use is the same as `chisq.test`
 | 
			
		||||
* Function `ratio` to transform a vector of values to a preset ratio
 | 
			
		||||
  * For example: `ratio(c(10, 500, 10), ratio = "1:2:1")` would return `130, 260, 130`
 | 
			
		||||
* ~~Function `ratio` to transform a vector of values to a preset ratio~~
 | 
			
		||||
  * ~~For example: `ratio(c(10, 500, 10), ratio = "1:2:1")` would return `130, 260, 130`~~
 | 
			
		||||
* Support for Addins menu in RStudio to quickly insert `%in%` or `%like%` (and give them keyboard shortcuts), or to view the datasets that come with this package
 | 
			
		||||
* Function `p.symbol` to transform p values to their related symbols: `0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1`
 | 
			
		||||
* Functions `clipboard_import` and `clipboard_export` as helper functions to quickly copy and paste from/to software like Excel and SPSS. These functions use the `clipr` package, but are a little altered to also support headless Linux servers (so you can use it in RStudio Server)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								R/freq.R
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								R/freq.R
									
									
									
									
									
								
							@@ -413,11 +413,9 @@ frequency_tbl <- function(x,
 | 
			
		||||
  df <- df %>% summarise(count = n())
 | 
			
		||||
 | 
			
		||||
  if (df$item %>% paste(collapse = ',') %like% '\033') {
 | 
			
		||||
    df <- df %>%
 | 
			
		||||
      mutate(item = item %>%
 | 
			
		||||
    # remove escape char
 | 
			
		||||
    # see https://en.wikipedia.org/wiki/Escape_character#ASCII_escape_character
 | 
			
		||||
               gsub('\033', ' ', ., fixed = TRUE))
 | 
			
		||||
    df <- df %>% mutate(item = item %>% gsub('\033', ' ', ., fixed = TRUE))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  # sort according to setting
 | 
			
		||||
 
 | 
			
		||||
@@ -51,6 +51,7 @@ test_that("frequency table works", {
 | 
			
		||||
  expect_output(septic_patients %>% select(1:7) %>% freq() %>% print())
 | 
			
		||||
  expect_output(septic_patients %>% select(1:8) %>% freq() %>% print())
 | 
			
		||||
  expect_output(septic_patients %>% select(1:9) %>% freq() %>% print())
 | 
			
		||||
  expect_output(print(freq(septic_patients$age), nmax = 20))
 | 
			
		||||
 | 
			
		||||
  # top 5
 | 
			
		||||
  expect_equal(
 | 
			
		||||
 
 | 
			
		||||
@@ -23,9 +23,18 @@ test_that("joins work", {
 | 
			
		||||
  expect_true(nrow(unjoined) < nrow(right))
 | 
			
		||||
  expect_true(nrow(unjoined) < nrow(full))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  expect_equal(nrow(inner_join_microorganisms("ESCCOL")), 1)
 | 
			
		||||
  expect_equal(nrow(inner_join_microorganisms("ESCCOL", by = c("bactid" = "bactid"))), 1)
 | 
			
		||||
  expect_warning(inner_join_microorganisms("Escherichia", by = c("bactid" = "genus")))
 | 
			
		||||
 | 
			
		||||
  expect_equal(nrow(left_join_microorganisms("ESCCOL")), 1)
 | 
			
		||||
  expect_warning(left_join_microorganisms("Escherichia", by = c("bactid" = "genus")))
 | 
			
		||||
 | 
			
		||||
  expect_equal(nrow(semi_join_microorganisms("ESCCOL")), 1)
 | 
			
		||||
  expect_equal(nrow(anti_join_microorganisms("ESCCOL")), 0)
 | 
			
		||||
 | 
			
		||||
  eexpect_warning(right_join_microorganisms("ESCCOL"))
 | 
			
		||||
  eexpect_warning(full_join_microorganisms("ESCCOL"))
 | 
			
		||||
 | 
			
		||||
})
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user