Skip to content

Commit

Permalink
Merge pull request #6 from psysciacc/check-folder
Browse files Browse the repository at this point in the history
Check folder
  • Loading branch information
doomlab authored Sep 19, 2024
2 parents a2448c0 + 2bfb9c6 commit 6f4df20
Show file tree
Hide file tree
Showing 45 changed files with 661 additions and 22 deletions.
446 changes: 429 additions & 17 deletions R/psa_check_folder.R

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions inst/03_Materials/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A readme file should exist in this folder.
1 change: 1 addition & 0 deletions inst/04_Procedure/lab_notebook.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
here,is,a,lab,notebook
2 changes: 1 addition & 1 deletion notes/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ roxygenize()

devtools::check()

devtools::install_github("psysciacc/psaverse")
devtools::install_github("psysciacc/psaverse@check-folder")
52 changes: 52 additions & 0 deletions tests/testthat/test-psa_check_folder.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# setup
tdir <- file.path(tempdir(), "PSA")
if (dir.exists(tdir)) unlink(tdir, recursive = TRUE)
dir.create(tdir, showWarnings = FALSE)


# Create model folder to check on
test_path <- system.file("tests", "testthat", package = "psaverse")
file.copy(test_path, tdir, recursive = TRUE)
test_pkg <- file.path(tdir, "testthat", "testCheckFolder")

# Activate dummy package to use the function on it
usethis::proj_activate(test_pkg)

test_that("ethics", {
expect_no_error(psa_check_folder(folder = "ethics"))
})

test_that("power", {
expect_no_error(psa_check_folder(folder = "power"))
})

test_that("materials", {
expect_no_error(psa_check_folder(folder = "materials"))
})

test_that("procedure", {
expect_no_error(psa_check_folder(folder = "procedure"))
})

test_that("data", {
expect_no_error(psa_check_folder(folder = "data"))
})

test_that("analysis", {
expect_no_error(psa_check_folder(folder = "analysis"))
})

test_that("communication", {
expect_no_error(psa_check_folder(folder = "communication"))
})

test_that("other", {
expect_no_error(psa_check_folder(folder = "other"))
})

test_that("all", {
expect_no_error(psa_check_folder(folder = "all"))
})

# clean up
unlink(tdir, recursive = TRUE)
2 changes: 2 additions & 0 deletions tests/testthat/testCheckFolder/.Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$
11 changes: 11 additions & 0 deletions tests/testthat/testCheckFolder/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package: testCheckFolder
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Author: Who wrote it
Maintainer: The package maintainer <[email protected]>
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
License: What license is it under?
Encoding: UTF-8
LazyData: true
1 change: 1 addition & 0 deletions tests/testthat/testCheckFolder/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exportPattern("^[[:alpha:]]+")
18 changes: 18 additions & 0 deletions tests/testthat/testCheckFolder/R/hello.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Hello, world!
#
# This is an example function named 'hello'
# which prints 'Hello, world!'.
#
# You can learn more about package authoring with RStudio at:
#
# https://r-pkgs.org
#
# Some useful keyboard shortcuts for package authoring:
#
# Install Package: 'Ctrl + Shift + B'
# Check Package: 'Ctrl + Shift + E'
# Test Package: 'Ctrl + Shift + T'

hello <- function() {
print("Hello, world!")
}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions tests/testthat/testCheckFolder/inst/01_Ethics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test
1 change: 1 addition & 0 deletions tests/testthat/testCheckFolder/inst/02_Power/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A readme file should exist in this folder.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some sort of power analysis should exist.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some sort of power analysis should exist.
1 change: 1 addition & 0 deletions tests/testthat/testCheckFolder/inst/03_Materials/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A readme file should exist in this folder.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
1 change: 1 addition & 0 deletions tests/testthat/testCheckFolder/inst/04_Procedure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A readme file should exist in this folder.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
here,is,a,lab,notebook
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
1 change: 1 addition & 0 deletions tests/testthat/testCheckFolder/inst/05_Data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A readme file should exist in this folder.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
1 change: 1 addition & 0 deletions tests/testthat/testCheckFolder/inst/06_Analysis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A readme file should exist in this folder.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file here to ensure the folder syncs to github.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A readme file should exist in this folder.
1 change: 1 addition & 0 deletions tests/testthat/testCheckFolder/inst/08_Other/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A readme file should exist in this folder.
12 changes: 12 additions & 0 deletions tests/testthat/testCheckFolder/man/hello.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\name{hello}
\alias{hello}
\title{Hello, World!}
\usage{
hello()
}
\description{
Prints 'Hello, world!'.
}
\examples{
hello()
}
20 changes: 20 additions & 0 deletions tests/testthat/testCheckFolder/testCheckFolder.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
90 changes: 86 additions & 4 deletions vignettes/psaverse.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,73 @@ You can update the description of the package using the `psa_update_description(

```{r eval = F}
psa_update_description(
package_title = NULL,
package_title = "SPAML IS GREAT",
description = NULL,
version = NULL,
license = NULL
)
# make sure default to null
# make sure this updates on the current project
# seems to update the original folder
# function to make sure you are in the right project
# make sure we aren't reloading each time
```

You can add authors to the package for other project monitors or the lead author of the paper.

```{r eval = F}
psa_add_author(
given = "Lucy",
family = "van Pelt",
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "LUCY-ORCID-ID"))
# why isn't comment working
```

## Create Folder Structure

`psa_create_folder("all")` will create the entire folder structure for the package, while you can also add one at a time.

Other options:

- "ethics": creates the "01_Ethics" folder.
- "power": creates the "02_Power" folder.
- "materials": creates the "03_Materials" folder.
- "procedure": creates the "04_Procedure" folder.
- "data": creates the "05_Data" folder.
- "analysis": creates the "06_Analysis" folder.
- "communication": creates the "07_Communication folder.
- "all": creates all eight main folders.
- Any other parameter option will be added into the 08_Other folder.

```{r eval = F}
# will create all folders
psa_create_folder("all")
# also allow people to use the "real" folder names like 01_Ethics
psa_create_folder("cheese")
```

## Add Dataset
## Add Documents

You can then manually move the files you need into the folder structure or use the `psa_add_documents()` function to add individual files or entire folders.

```{r eval = F}
psa_data(
psa_add_documents(
folder = "ethics", # where should it go
path = "~/Downloads", # to a single file or directory
should_replace = FALSE, # overwrite existing files?
recursive = FALSE # better explain this in docs
)
# recheck copying individual files
# path should allow vector of file paths like a list of PDFs
# or a directory
# or single file
```

## Add R Package Dependencies
Expand All @@ -58,9 +113,12 @@ psa_dependencies(
scan_folder = "inst",
add_package = NULL # has to be one at a time
)
# add qmd files
# allow for vector of packages to be added
```

## Add R Package to PSA GitHub
## Add this Package to PSA GitHub

First, you should confirm you have the ability to push to the PsySciAcc github organization at https://github.com/psysciacc. Please ask to be added to the team.

Expand All @@ -69,3 +127,27 @@ Second, you can use the `psa_git()` function to initialize your new project as a
```{r eval = F}
psa_git()
```

## Check Package Folders

This function will check that you meet the minimum requires for documentation and files for the PSA folder structure. You will receive information on what you are missing.

Options: "ethics", "power", "materials", "procedure", "data", "analysis", "communication", "all".

```{r eval = F}
psa_check_folder(folder = "ethics")
# be sure to set working directory to the project so make it a global function
```

working folder should not be empty if so make it "."

can't write the testthat (or subfolders) for CRAN, so make sure it's writing to a temp directory
(check scienceverse)

https://scienceverse.github.io/scienceverse/index.html
https://github.com/scienceverse/scienceverse/

https://github.com/debruine/booktem/blob/master/tests/testthat/test-create_book.R
- preclean up
- and then if stops be sure to clean up as well

0 comments on commit 6f4df20

Please sign in to comment.