From 88788dd320255eb0e601be396d0f8ede571a3643 Mon Sep 17 00:00:00 2001 From: Ludovic Vannoorenberghe Date: Mon, 2 Oct 2017 23:24:02 +0200 Subject: [PATCH] disable test creating a .RProfile --- R/utils.R | 11 +++++++---- tests/testthat/test-defaults.R | 19 ------------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/R/utils.R b/R/utils.R index e0e0d71..5ca3233 100644 --- a/R/utils.R +++ b/R/utils.R @@ -60,11 +60,8 @@ get_package_from_URL <- function(url){ } get_r_profile <- function(){ - if (!file.exists(file.path(Sys.getenv("HOME"),".Rprofile"))) { - file.create(file.path(Sys.getenv("HOME"), ".Rprofile"), quiet=TRUE) - } Rprofile <- file.path(Sys.getenv("HOME"), ".Rprofile") - return (Rprofile) + return (file(Rprofile, "w+")) } concat <- function(x) { @@ -72,6 +69,9 @@ concat <- function(x) { } is_in_profile <- function(targets) { + if (!file.exists(file.path(Sys.getenv("HOME"),".Rprofile"))) { + return (FALSE) + } any(targets %in% readLines(get_r_profile())) } @@ -83,6 +83,9 @@ add_to_profile <- function(the_line, old_lines = "") { } remove_from_profile <- function(the_line, old_lines = "") { + if (!file.exists(file.path(Sys.getenv("HOME"),".Rprofile"))) { + return () + } rprofile <- get_r_profile() lines <- readLines(rprofile) # Keep all non-matching lines diff --git a/tests/testthat/test-defaults.R b/tests/testthat/test-defaults.R index c54a622..065c3b7 100644 --- a/tests/testthat/test-defaults.R +++ b/tests/testthat/test-defaults.R @@ -1,24 +1,5 @@ context("defaults") -test_that("autoloads",{ - disable_autoload() - expect_false(autoload_line %in% readLines(get_r_profile())) - expect_false(is_autoload()) - enable_autoload() - expect_true(autoload_line %in% readLines(get_r_profile())) - expect_true(is_autoload()) - disable_autoload() - expect_false(autoload_line %in% readLines(get_r_profile())) - expect_false(is_autoload()) - enable_autoload() - write(autoload_line_old, file = get_r_profile(), append = TRUE) - expect_true(is_autoload()) - disable_autoload() - expect_false(autoload_line %in% readLines(get_r_profile())) - expect_false(autoload_line_old %in% readLines(get_r_profile())) - expect_false(is_autoload()) -}) - test_that("overrides", { disable_rdocs() expect_false(rdocs_active())