Skip to content

Commit

Permalink
feat create_renv_for_dev can work even outside of an R packages
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentGuyader committed Feb 17, 2024
1 parent 78f97a7 commit 2df6318
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 1 deletion.
24 changes: 23 additions & 1 deletion R/create_renv.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ create_renv_for_dev <- function(path = ".",
stop("'renv' is required. Please install it before.")
}

path_orig <- path
path <- normalizePath(path)

if (!is.null(dev_pkg) && "_default" %in% dev_pkg) {
Expand All @@ -68,6 +69,11 @@ create_renv_for_dev <- function(path = ".",
dev_pkg <- c(extra_dev_pkg, dev_pkg[dev_pkg != "_default"])
}


# s'il n y pas de fichier DESCRIPTION on va chercher l'information ailleurs

if (file.exists(file.path(path, "DESCRIPTION"))){

if (isTRUE(document)) {
# Use a temporary config_file for renv
config_file <- file.path(path, "dev", "config_attachment.yaml")
Expand Down Expand Up @@ -101,7 +107,23 @@ create_renv_for_dev <- function(path = ".",
att_from_description(path = file.path(path, "DESCRIPTION"),field = fields),
dev_pkg
)
)
)} else {
cli::cli_alert_info("No DESCRIPTION file found")
cli::cli_alert_info( paste(
"we wil parse qmd files,Rmd files and R scripts i ",path,
"."
))


pkg_list <- unique(
c(
att_from_qmds(path = path,recursive = TRUE),
att_from_rmds(path = path,recursive = TRUE),
att_from_rscripts(path = path,recursive = TRUE),
dev_pkg
)
)
}

# Extra folders
folder_to_include_relative <- folder_to_include
Expand Down
2 changes: 2 additions & 0 deletions inst/dummyfolder/global.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
library(dplyr)
library(sudoku)
28 changes: 28 additions & 0 deletions inst/dummyfolder/server.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#

library(shiny)

# Define server logic required to draw a histogram
function(input, output, session) {

output$distPlot <- renderPlot({

# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)

# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white',
xlab = 'Waiting time to next eruption (in mins)',
main = 'Histogram of waiting times')

})

}
33 changes: 33 additions & 0 deletions inst/dummyfolder/ui.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# This is the user-interface definition of a Shiny web application. You can
# run the application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#

library(shiny)

# Define UI for application that draws a histogram
fluidPage(

# Application title
titlePanel("Old Faithful Geyser Data"),

# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),

# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
49 changes: 49 additions & 0 deletions tests/testthat/test-renv_create2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# These tests can not run on CRAN
skip_on_cran()

if (length(find.package("extrapackage", quiet = TRUE)) != 0) {
unlink(find.package("extrapackage", quiet = TRUE), recursive = TRUE)
}

# test on dummy package
tmpdir <- tempfile(pattern = "pkgrenv2")
dir.create(tmpdir)
file.copy(
system.file("dummyfolder", package = "attachment"), tmpdir,
recursive = TRUE
)
dummyfolder <- file.path(tmpdir, "dummyfolder")
lock_ <- file.path(tmpdir, "my_lock.lock")


expect_message({

my_renv_ <- create_renv_for_dev(
path = dummyfolder,
install_if_missing = FALSE,
output = lock_,
# force generation of a lockfile even when pre-flight validation checks have failed?
force = TRUE)}
)





test_that("create_renv_for_dev creates lock files even without DESCRIPTION file", {
expect_true(file.exists(lock_))
})

# print(my_renv_extra)


renv_content <- getFromNamespace("lockfile", "renv")(my_renv_)


test_that("lockfile are correct renv files", {
expect_s3_class(renv_content, "renv_lockfile_api")
expect_true("dplyr" %in% names(renv_content$data()$Packages))
expect_true("sudoku" %in% names(renv_content$data()$Packages))
})


0 comments on commit 2df6318

Please sign in to comment.