diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index dc721eb..33f3114 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -21,7 +21,6 @@ jobs: - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - - {os: ubuntu-latest, r: 'release'} - {os: ubuntu-latest, r: 'oldrel-1'} env: diff --git a/R/detect_os_compat.r b/R/detect_os_compat.r new file mode 100644 index 0000000..25b078a --- /dev/null +++ b/R/detect_os_compat.r @@ -0,0 +1,8 @@ +# Detect whether the user is on a mac or Windows OS (compatable with Frescalo) or a different OS. This function is needed to work with Mockery functions in tests +detect_os_compat <- function() { + if (Sys.info()["sysname"] %in% c("Darwin", "Windows")) { + return(TRUE) + } else { + return(FALSE) + } +} diff --git a/R/run_fresc_file.R b/R/run_fresc_file.R index 726611d..ea0829f 100644 --- a/R/run_fresc_file.R +++ b/R/run_fresc_file.R @@ -17,6 +17,11 @@ function( Plot=TRUE ){ + +if (!detect_os_compat()) { + stop("Apologies, Frescalo is currently only avaiable on mac and Windows operating systems.") +} + # BODY OF FUNCTION # Print status to screen cat("\nSAVING DATA TO FRESCALO WORKING DIRECTORY\n",rep("*",20),"\n\n", sep="") diff --git a/tests/testthat/testerrorChecks.R b/tests/testthat/testerrorChecks.R deleted file mode 100755 index 4b80a67..0000000 --- a/tests/testthat/testerrorChecks.R +++ /dev/null @@ -1,171 +0,0 @@ -context("Test errorChecks") - -set.seed(seed = 128) - -# Create data -n <- 3000 #size of dataset -nyr <- 10 # number of years in data -nSamples <- 30 # set number of dates -nSites <- 15 # set number of sites - -# Create somes dates -first <- as.POSIXct(strptime("2010/01/01", "%Y/%m/%d")) -last <- as.POSIXct(strptime(paste(2010+(nyr-1),"/12/31", sep=''), "%Y/%m/%d")) -dt <- last-first -rDates <- first + (runif(nSamples)*dt) - -# taxa are set as random letters -taxa <- sample(letters, size = n, TRUE) - -# three sites are visited randomly -site <- sample(paste('A', 1:nSites, sep=''), size = n, TRUE) - -# the date of visit is selected at random from those created earlier -time_period <- sample(rDates, size = n, TRUE) -time_period_missing <- sample(c(rDates, NA), size = n, TRUE) - -dist_sub <- rnorm(n, 10, 1) -sim_sub <- rnorm(n, 10, 1) - -dist_sub_fac <- as.factor(rnorm(n, 10, 1)) -sim_sub_fac <- as.factor(rnorm(n, 10, 1)) - - -dist_sub_chr <- as.character(rnorm(n, 10, 1)) -sim_sub_chr <- as.character(rnorm(n, 10, 1)) - -dist_sub_fac <- as.factor(rnorm(n, 10, 1)) -sim_sub_fac <- as.factor(rnorm(n, 10, 1)) - - -# combine this to a dataframe -df <- data.frame(taxa = taxa, - site = site, - time_period = as.character(time_period), - time_period_missing = time_period_missing, - dist_sub = dist_sub, - sim_sub = sim_sub, - dist_sub_chr = dist_sub_chr, - sim_sub_chr = sim_sub_chr, - dist_sub_fac = dist_sub_fac, - sim_sub_fac = sim_sub_fac) - - -useIterations_num <- 1 -useIterations_chr <- "TRUE" - - -temp <- tempfile() - -dir.create(temp) - -test_that("Test errors", { - expect_error(errorChecks(startDate = df$time_period), - 'startDate is not in a date format. This should be of class "Date" or "POSIXct"') - - expect_error(errorChecks(startDate = df$time_period_missing), - 'startDate must not contain NAs') - - expect_error(errorChecks(Date = df$time_period), - 'Date must be a data.frame or date vector') - - expect_error(errorChecks(Date = df$time_period_missing), - 'Date must not contain NAs') - - expect_error(errorChecks(endDate = df$time_period), - 'endDate is not in a date format. This should be of class "Date" or "POSIXct"') - - expect_error(errorChecks(endDate = df$time_period_missing), - 'endDate must not contain NAs') - - expect_error(errorChecks(dist_sub = df$dist_sub_chr, sim_sub = df$sim_sub), - 'dist_sub must be integer or numeric') - - expect_error(errorChecks(dist_sub = df$dist_sub, sim_sub = df$sim_sub_chr), - 'sim_sub must be integer or numeric') - - expect_error(errorChecks(dist_sub = df$dist_sub_fac, sim_sub = df$sim_sub), - 'dist_sub must be integer or numeric') - - expect_error(errorChecks(dist_sub = df$dist_sub, sim_sub = df$sim_sub_fac), - 'sim_sub must be integer or numeric') - - expect_error(errorChecks(useIterations = useIterations_chr), - 'useIterations must be logical') - - expect_error(errorChecks(useIterations = useIterations_num), - 'useIterations must be logical') - - expect_error(errorChecks(iterations = "1000"), - 'iterations must be numeric or integer') - - expect_error(errorChecks(family = "Poisson"), - 'family must be either Binomial or Bernoulli') - - expect_error(errorChecks(n_iterations = 1000, burnin = 500, thinning = 1100, n_chains = 3), - 'thinning must not be larger that the number of iteration (n_iterations)', - fixed = TRUE) - - expect_error(errorChecks(n_iterations = "1000", burnin = 500, thinning = 5, n_chains = 3), - 'n_iterations should be numeric') - - expect_error(errorChecks(n_iterations = 1000, burnin = "500", thinning = 5, n_chains = 3), - 'burnin should be numeric') - - expect_error(errorChecks(n_iterations = 1000, burnin = 500, thinning = "5", n_chains = 3), - 'thinning should be numeric') - - expect_error(errorChecks(n_iterations = 1000, burnin = 500, thinning = 5, n_chains = "3"), - 'n_chains should be numeric') - - expect_error(errorChecks(seed = "1"), - 'seed muct be numeric') - - expect_error(errorChecks(year_col = NA, start_col = NA, end_col = time_period[1]), - 'year_col or start_col and end_col must be given') - - expect_error(errorChecks(year_col = NA, start_col = df$time_period[1], end_col = NA), - 'year_col or start_col and end_col must be given') - - expect_error(errorChecks(year_col = NA, start_col = df$time_period[1], end_col = df$time_period[1]), - 'year_col cannot be used at the same time as start_col and end_col') - - expect_error(errorChecks(phi = 0.1), - "phi is outside permitted range of 0.50 to 0.95") - - expect_error(errorChecks(phi = 0.99), - "phi is outside permitted range of 0.50 to 0.95") - - expect_error(errorChecks(alpha = 0.05), - "alpha is outside permitted range of 0.08 to 0.50") - - expect_error(errorChecks(alpha = 0.99), - "alpha is outside permitted range of 0.08 to 0.50") - - expect_error(errorChecks(non_benchmark_sp = c(1,5,10,12)), - 'non_benchmark_sp must be a character vector') - - expect_error(errorChecks(non_benchmark_sp = 12), - 'non_benchmark_sp must be a character vector') - - expect_error(errorChecks(fres_site_filter = c(1,5,10,12)), - 'fres_site_filter must be a character vector') - - expect_error(errorChecks(fres_site_filter = 12), - 'fres_site_filter must be a character vector') - - expect_error(errorChecks(time_periods = as.matrix(df$time_period)), - 'time_periods should be a data.frame. e.g. "data.frame(start=c(1980,1990),end=c(1989,1999))"', - fixed = TRUE) - - expect_error(errorChecks(frespath = temp), - "filepath is not the path to a '.exe' file") - - expect_error(errorChecks(frespath = "file.exe"), - 'file.exe does not exist') - - expect_error(errorChecks(site = c('a', 'b', '')), - "site must not contain empty values (i.e. '')", - fixed = TRUE) - -}) diff --git a/tests/testthat/testfrescalo.r b/tests/testthat/testfrescalo.r index 87c43b1..1478bd5 100755 --- a/tests/testthat/testfrescalo.r +++ b/tests/testthat/testfrescalo.r @@ -1,227 +1,249 @@ -context("Test frescalo") - ### Frescalo testing is currently skipped if not on a ### ### windows machine, or if libcurl is not supported. ### # Create data -n <- 1500 #size of dataset +n <- 1500 # size of dataset nyr <- 20 # number of years in data nSamples <- 100 # set number of dates nSites <- 50 # set number of sites set.seed(125) # Create somes dates -first <- as.Date(strptime("1980/01/01", "%Y/%m/%d")) -last <- as.Date(strptime(paste(1980+(nyr-1),"/12/31", sep=''), "%Y/%m/%d")) -dt <- last-first -rDates <- first + (runif(nSamples)*dt) +first <- as.Date(strptime("1980/01/01", "%Y/%m/%d")) +last <- as.Date(strptime(paste(1980 + (nyr - 1), "/12/31", sep = ""), "%Y/%m/%d")) +dt <- last - first +rDates <- first + (runif(nSamples) * dt) # taxa are set as random letters taxa <- sample(letters, size = n, TRUE) # three sites are visited randomly -site <- sample(paste('a', 11:(nSites + 10), sep=''), size = n, TRUE) +site <- sample(paste("a", 11:(nSites + 10), sep = ""), size = n, TRUE) # the date of visit is selected at random from those created earlier time_period <- sample(rDates, size = n, TRUE) -df1 <- data.frame(taxa = taxa, - site = site, - year = as.numeric(format(time_period, '%Y')), - startdate = time_period, - enddate = time_period + 500) +df1 <- data.frame( + taxa = taxa, + site = site, + year = as.numeric(format(time_period, "%Y")), + startdate = time_period, + enddate = time_period + 500 +) allsites <- sort(unique(site)) weights <- merge(allsites, allsites) weights$W <- runif(n = nrow(weights), min = 0, max = 1) -frespath <- file.path(tempdir(), 'fres.exe') +frespath <- file.path(tempdir(), "fres.exe") -toms_PC <- Sys.info()['nodename'] == "WLL-3RHYM53" +# Save the system info as an object +system_info <- Sys.info() -if(toms_PC) frespath <- 'C:/Frescalo_3a_windows.exe' +test_that("Does the function stop when the operating system is not mac or Windows", { -test_that("Test errors", { - - skip_on_appveyor() - skip_on_travis() - if (!capabilities('libcurl')) skip('skipping as libcurl not supported') - if(grepl("mac", .Platform$pkgType)) skip('Frescalo exe does not run on Mac OS') - if (.Platform$OS.type == "windows" & !toms_PC) skip('Carbon black blocks Frescalo') - - if(!toms_PC){ - if(.Platform$OS.type == "windows"){ - download.file(url = 'https://github.com/BiologicalRecordsCentre/frescalo/raw/master/Frescalo_3a_windows.exe', - destfile = frespath, - method = "libcurl", - mode = 'wb', quiet = TRUE) - } else if(.Platform$OS.type == "unix"){ - download.file(url = 'https://github.com/BiologicalRecordsCentre/frescalo/raw/master/Frescalo_3a_linux.exe', - destfile = frespath, - method = "libcurl", - quiet = TRUE) - system(command = paste('chmod', '+x', normalizePath(frespath))) - } else{ - stop(paste('frescalo is not supported on', .Platform$OS.type)) + if (system_info["sysname"] == "Darwin") { + skip("Frescalo installation failures") + } + + temp <- tempfile(pattern = "dir") + dir.create(temp) + + with_mocked_bindings( + "detect_os_compat" = function() FALSE, + { + expect_error(suppressWarnings(frescalo( + Data = df1, + Fres_weights = weights, + frespath = frespath, + time_periods = data.frame(start = c(1980, 1990), end = c(1989, 1999)), + site_col = "site", + sp_col = "taxa", + year = "year", + sinkdir = temp + )), "Apologies, Frescalo is currently only avaiable on mac and Windows operating systems.") + } + ) +}) + + if (system_info["sysname"] == "Windows") { + download.file( + url = "https://github.com/BiologicalRecordsCentre/frescalo/raw/master/Frescalo_3a_windows.exe", + destfile = frespath, + method = "libcurl", + mode = "wb", quiet = TRUE + ) + } else if (system_info["sysname"] == "Darwin") { + download.file( + url = "https://github.com/BiologicalRecordsCentre/frescalo/raw/master/Frescalo_3a_linux.exe", + destfile = frespath, + method = "libcurl", + quiet = TRUE + ) + + system(command = paste("chmod", "+x", normalizePath(frespath))) } + +test_that("Test errors", { + + if (system_info["sysname"] == "Darwin") { + skip("Frescalo installation failures") } - - temp <- tempfile(pattern = 'dir') + + temp <- tempfile(pattern = "dir") dir.create(temp) - expect_error(frescalo(Data = df1, - frespath = frespath, - time_periods = data.frame(start=c(1980,1990),end=c(1989,1999)), - site_col = 'site', - sp_col = 'FOO', - year = 'year', - sinkdir = temp), - 'FOO is not the name of a column in data') - - expect_error(frescalo(Data = df1, - frespath = frespath, - time_periods = c(1980,1990,1989,1999), - site_col = 'site', - sp_col = 'taxa', - year = 'year', - sinkdir = temp), - 'time_periods should be a data.frame') - - expect_error(frescalo(Data = df1, - frespath = frespath, - time_periods = data.frame(start=c(1980,1850),end=c(1989,1999)), - site_col = 'site', - sp_col = 'taxa', - year = 'year', - sinkdir = temp), - 'In time_periods year ranges should not overlap') + expect_error( + suppressWarnings(frescalo( + Data = df1, + frespath = frespath, + time_periods = data.frame(start = c(1980, 1990), end = c(1989, 1999)), + site_col = "site", + sp_col = "FOO", + year = "year", + sinkdir = temp + )), + "FOO is not the name of a column in data" + ) + expect_error( + suppressWarnings(frescalo( + Data = df1, + frespath = frespath, + time_periods = c(1980, 1990, 1989, 1999), + site_col = "site", + sp_col = "taxa", + year = "year", + sinkdir = temp + )), + "time_periods should be a data.frame" + ) - expect_error(frescalo(Data = df1, - frespath = frespath, - time_periods = data.frame(start=c(1980,1990),end=c(1989,1999)), - site_col = 'site', - sp_col = 'taxa', - year = 'year', - sinkdir = temp), - 'the sites in your data do not match those in your weights file') - -}) + expect_error( + suppressWarnings(frescalo( + Data = df1, + frespath = frespath, + time_periods = data.frame(start = c(1980, 1850), end = c(1989, 1999)), + site_col = "site", + sp_col = "taxa", + year = "year", + sinkdir = temp + )), + "In time_periods year ranges should not overlap" + ) + expect_error( + suppressWarnings(frescalo( + Data = df1, + frespath = frespath, + time_periods = data.frame(start = c(1980, 1990), end = c(1989, 1999)), + site_col = "site", + sp_col = "taxa", + year = "year", + sinkdir = temp + )), + "the sites in your data do not match those in your weights file" + ) + + }) test_that("Runs without error", { - skip_on_appveyor() - skip_on_travis() - if (!capabilities('libcurl')) skip('skipping as libcurl not supported') - if(grepl("mac", .Platform$pkgType)) skip('Frescalo exe does not run on Mac OS') - if (.Platform$OS.type == "windows" & !toms_PC) skip('Carbon black blocks Frescalo') - + if (system_info["sysname"] == "Darwin") { + skip("Frescalo installation failures") + } + + if (!detect_os_compat()) { + skip("Operating system incompatible with Frescalo") + } + # This first run is done using years - temp <- tempfile(pattern = 'dir') + temp <- tempfile(pattern = "dir") dir.create(temp) - sink(file.path(temp, 'null')) - fres_try <- try(frescalo(Data = df1, - Fres_weights = weights, - frespath = frespath, - time_periods = data.frame(start=c(1980,1990),end=c(1989,1999)), - site_col = 'site', - sp_col = 'taxa', - year = 'year', - sinkdir = temp), - silent=TRUE - ) - sink() + ##sink(file.path(temp, "null")) + fres_try <- suppressWarnings(frescalo( + Data = df1, + Fres_weights = weights, + frespath = frespath, + time_periods = data.frame(start = c(1980, 1990), end = c(1989, 1999)), + site_col = "site", + sp_col = "taxa", + year = "year", + sinkdir = temp + )) + ##sink() unlink(temp, recursive = TRUE) - + expect_equal(class(fres_try), "frescalo") expect_true("paths" %in% names(fres_try) & - "trend" %in% names(fres_try) & - "stat" %in% names(fres_try) & - "freq" %in% names(fres_try) & - "log" %in% names(fres_try) & - "lm_stats" %in% names(fres_try)) - + "trend" %in% names(fres_try) & + "stat" %in% names(fres_try) & + "freq" %in% names(fres_try) & + "log" %in% names(fres_try) & + "lm_stats" %in% names(fres_try)) + dir.create(temp) - sink(file.path(temp, 'null')) - fres_try <- try(frescalo(Data = df1, - Fres_weights = weights, - start_col = 'startdate', - end_col = 'enddate', - frespath = frespath, - time_periods = data.frame(start=c(1980,1990),end=c(1989,1999)), - site_col = 'site', - sp_col = 'taxa', - year = 'year', - sinkdir = temp), - silent=TRUE - ) - sink() + #sink(file.path(temp, "null")) + fres_try <- suppressWarnings(frescalo( + Data = df1, + Fres_weights = weights, + start_col = "startdate", + end_col = "enddate", + frespath = frespath, + time_periods = data.frame(start = c(1980, 1990), end = c(1989, 1999)), + site_col = "site", + sp_col = "taxa", + year = "year", + sinkdir = temp + )) + #sink() unlink(temp, recursive = TRUE) - + expect_equal(class(fres_try), "frescalo") expect_true("paths" %in% names(fres_try) & - "trend" %in% names(fres_try) & - "stat" %in% names(fres_try) & - "freq" %in% names(fres_try) & - "log" %in% names(fres_try) & - "lm_stats" %in% names(fres_try)) - + "trend" %in% names(fres_try) & + "stat" %in% names(fres_try) & + "freq" %in% names(fres_try) & + "log" %in% names(fres_try) & + "lm_stats" %in% names(fres_try)) + # test a very low value of phi - temp <- tempfile(pattern = 'dir') + temp <- tempfile(pattern = "dir") dir.create(temp) - sink(file.path(temp, 'null')) - fres_try <- try(suppressWarnings(frescalo(Data = df1, - phi = 0.51, - Fres_weights = weights, - frespath = frespath, - time_periods = data.frame(start=c(1980,1990),end=c(1989,1999)), - site_col = 'site', - sp_col = 'taxa', - year = 'year', - sinkdir = temp)), - silent=TRUE) - sink() + #sink(file.path(temp, "null")) + fres_try <- suppressWarnings(frescalo( + Data = df1, + phi = 0.51, + Fres_weights = weights, + frespath = frespath, + time_periods = data.frame(start = c(1980, 1990), end = c(1989, 1999)), + site_col = "site", + sp_col = "taxa", + year = "year", + sinkdir = temp + )) + #sink() unlink(temp, recursive = TRUE) - + expect_equal(class(fres_try), "frescalo") expect_true("paths" %in% names(fres_try) & - "trend" %in% names(fres_try) & - "stat" %in% names(fres_try) & - "freq" %in% names(fres_try) & - "log" %in% names(fres_try) & - "lm_stats" %in% names(fres_try)) - + "trend" %in% names(fres_try) & + "stat" %in% names(fres_try) & + "freq" %in% names(fres_try) & + "log" %in% names(fres_try) & + "lm_stats" %in% names(fres_try)) }) - -# Create data -n <- 1500 #size of dataset -nyr <- 20 # number of years in data -nSamples <- 100 # set number of dates -nSites <- 50 # set number of sites -set.seed(125) - -# Create somes dates -first <- as.Date(strptime("1980/01/01", "%Y/%m/%d")) -last <- as.Date(strptime(paste(1980+(nyr-1),"/12/31", sep=''), "%Y/%m/%d")) -dt <- last-first -rDates <- first + (runif(nSamples)*dt) - -# taxa are set as random letters -taxa <- sample(letters, size = n, TRUE) - # three sites are visited randomly -site <- sample(paste('SK', 11:(nSites + 10), sep=''), size = n, TRUE) - -# the date of visit is selected at random from those created earlier -time_period <- sample(rDates, size = n, TRUE) +site <- sample(paste("SK", 11:(nSites + 10), sep = ""), size = n, TRUE) -df1 <- data.frame(taxa = taxa, - site = site, - year = as.numeric(format(time_period, '%Y')), - startdate = time_period, - enddate = time_period + 500) +df1 <- data.frame( + taxa = taxa, + site = site, + year = as.numeric(format(time_period, "%Y")), + startdate = time_period, + enddate = time_period + 500 +) allsites <- sort(unique(site)) @@ -229,68 +251,52 @@ weights <- merge(allsites, allsites) weights$W <- runif(n = nrow(weights), min = 0, max = 1) test_that("Test plotting", { - - skip_on_travis() - skip_on_appveyor() - if (!capabilities('libcurl')) skip('skipping as libcurl not supported') - if(grepl("mac", .Platform$pkgType)) skip('Frescalo exe does not run on Mac OS') - if (.Platform$OS.type == "windows" & !toms_PC) skip('Carbon black blocks Frescalo') - + + if (system_info["sysname"] == "Darwin") { + skip("Frescalo installation failures") + } + + if (!detect_os_compat()) { + skip("Operating system incompatible with Frescalo") + } + # test plotting - temp <- tempfile(pattern = 'dir') + temp <- tempfile(pattern = "dir") dir.create(temp) - sink(file.path(temp, 'null')) - fres_try <- try(frescalo(Data = df1, - Fres_weights = weights, - frespath = frespath, - time_periods = data.frame(start=c(1980,1990),end=c(1989,1999)), - site_col = 'site', - sp_col = 'taxa', - year = 'year', - plot_fres = TRUE, - sinkdir = temp), - silent=TRUE - ) - sink() + #sink(file.path(temp, "null")) + fres_try <- suppressWarnings(frescalo( + Data = df1, + Fres_weights = weights, + frespath = frespath, + time_periods = data.frame(start = c(1980, 1990), end = c(1989, 1999)), + site_col = "site", + sp_col = "taxa", + year = "year", + plot_fres = TRUE, + sinkdir = temp + )) + #sink() unlink(temp, recursive = TRUE) - + expect_equal(class(fres_try), "frescalo") expect_true("paths" %in% names(fres_try) & - "trend" %in% names(fres_try) & - "stat" %in% names(fres_try) & - "freq" %in% names(fres_try) & - "log" %in% names(fres_try) & - "lm_stats" %in% names(fres_try)) + "trend" %in% names(fres_try) & + "stat" %in% names(fres_try) & + "freq" %in% names(fres_try) & + "log" %in% names(fres_try) & + "lm_stats" %in% names(fres_try)) }) - -# Create data -n <- 15000 #size of dataset -nyr <- 20 # number of years in data -nSamples <- 100 # set number of dates -nSites <- 50 # set number of sites -set.seed(125) - -# Create somes dates -first <- as.Date(strptime("1980/01/01", "%Y/%m/%d")) -last <- as.Date(strptime(paste(1980+(nyr-1),"/12/31", sep=''), "%Y/%m/%d")) -dt <- last-first -rDates <- first + (runif(nSamples)*dt) - -# taxa are set as random letters -taxa <- sample(letters, size = n, TRUE) - # three sites are visited randomly -site <- sample(paste('A', 1:nSites, sep=''), size = n, TRUE) - -# the date of visit is selected at random from those created earlier -time_period <- sample(rDates, size = n, TRUE) +site <- sample(paste("A", 1:nSites, sep = ""), size = n, TRUE) -df1 <- data.frame(taxa = taxa, - site = site, - year = as.numeric(format(time_period, '%Y')), - startdate = time_period, - enddate = time_period + 500) +df1 <- data.frame( + taxa = taxa, + site = site, + year = as.numeric(format(time_period, "%Y")), + startdate = time_period, + enddate = time_period + 500 +) allsites <- sort(unique(site)) @@ -298,36 +304,38 @@ weights <- merge(allsites, allsites) weights$W <- runif(n = nrow(weights), min = 0, max = 1) test_that("Runs high value of phi", { - - skip_on_appveyor() - skip_on_travis() - if (!capabilities('libcurl')) skip('skipping as libcurl not supported') - if(grepl("mac", .Platform$pkgType)) skip('Frescalo exe does not run on Mac OS') - if (.Platform$OS.type == "windows" & !toms_PC) skip('Carbon black blocks Frescalo') - + + if (system_info["sysname"] == "Darwin") { + skip("Frescalo installation failures") + } + + if (!detect_os_compat()) { + skip("Operating system incompatible with Frescalo") + } + # test a very low value of phi - temp <- tempfile(pattern = 'dir') + temp <- tempfile(pattern = "dir") dir.create(temp) - sink(file.path(temp, 'null')) - fres_try <- try(suppressWarnings(frescalo(Data = df1, - Fres_weights = weights, - phi = NULL, - frespath = frespath, - time_periods = data.frame(start=c(1980,1990),end=c(1989,1999)), - site_col = 'site', - sp_col = 'taxa', - year = 'year', - sinkdir = temp)), - silent=TRUE) - sink() + #sink(file.path(temp, "null")) + fres_try <- suppressWarnings(frescalo( + Data = df1, + Fres_weights = weights, + phi = NULL, + frespath = frespath, + time_periods = data.frame(start = c(1980, 1990), end = c(1989, 1999)), + site_col = "site", + sp_col = "taxa", + year = "year", + sinkdir = temp + )) + #sink() unlink(temp, recursive = TRUE) - + expect_equal(class(fres_try), "frescalo") expect_true("paths" %in% names(fres_try) & - "trend" %in% names(fres_try) & - "stat" %in% names(fres_try) & - "freq" %in% names(fres_try) & - "log" %in% names(fres_try) & - "lm_stats" %in% names(fres_try)) - + "trend" %in% names(fres_try) & + "stat" %in% names(fres_try) & + "freq" %in% names(fres_try) & + "log" %in% names(fres_try) & + "lm_stats" %in% names(fres_try)) })