Skip to content

Commit

Permalink
Merge pull request #21 from TanguyBarthelemy/master
Browse files Browse the repository at this point in the history
Update readme and styler package
  • Loading branch information
TanguyBarthelemy authored Jan 26, 2024
2 parents 5f31ff8 + bba07ce commit afced6d
Show file tree
Hide file tree
Showing 18 changed files with 1,154 additions and 714 deletions.
29 changes: 14 additions & 15 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
os: [ 'ubuntu-latest', 'windows-latest', 'macOS-latest' ]
r: [ 'devel', 'release', 'oldrel-1', '4.2.1', '4.1.1', '4.1.3', '3.6.1' ]
r: [ 'devel', 'release', 'oldrel-1', '4.2.3', '4.2.1', '4.1.1', '4.1.3', '4.0.5', '3.6.1' ]
java: [ '8', '13', '17', '19' ]
# java: [ '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19' ]
include:
Expand All @@ -33,7 +33,7 @@ jobs:
# - {os: ubuntu-latest, r: '3.6.1'}
# - {os: ubuntu-latest, r: '4.1.3'}
# - {os: ubuntu-latest, r: '4.1.1'}
# - {os: ubuntu-latest, r: '4.2.1'}
# - {os: ubuntu-latest, r: '4.2.1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -43,7 +43,7 @@ jobs:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- name: Setup java (x64)
uses: actions/setup-java@v3
if: matrix.java != '19'
Expand All @@ -52,7 +52,7 @@ jobs:
java-package: jdk
distribution: 'zulu'
architecture: x64

- name: Setup java (x64)
uses: actions/setup-java@v3
if: matrix.java == '19'
Expand All @@ -61,7 +61,7 @@ jobs:
java-package: jdk
distribution: 'temurin'
architecture: x64

- name: Setup java (x86)
uses: actions/setup-java@v3
if: runner.os == 'windows' && matrix.java != '19'
Expand All @@ -70,7 +70,7 @@ jobs:
java-package: jdk
distribution: 'zulu'
architecture: x86

- name: Setup java (x86)
uses: actions/setup-java@v3
if: runner.os == 'windows' && matrix.java == '19'
Expand All @@ -79,14 +79,14 @@ jobs:
java-package: jdk
distribution: 'temurin'
architecture: x86

- name: Set up R
uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.r }}
http-user-agent: ${{ matrix.http-user-agent }}
use-public-rspm: true

# Pour macos, qqs installation supplémentaires
- name: "[Stage] [macOS] Install libgit2"
if: runner.os == 'macOS'
Expand All @@ -95,7 +95,7 @@ jobs:
- name: "[Stage] [macOS] Install system libs for pkgdown"
if: runner.os == 'macOS'
run: brew install harfbuzz fribidi

- name: Configure java pour macos
if: runner.os == 'macOS'
run: R CMD javareconf
Expand All @@ -105,27 +105,26 @@ jobs:
if: ${{ runner.os != 'macOS' }}
with:
extra-packages: any::rcmdcheck, XML

# Pour macos, qqs installation supplémentaires
- name: Install dependencies
uses: r-lib/actions/setup-r-dependencies@v2
if: ${{ runner.os == 'macOS' }}
with:
packages: knitr, kableExtra, rmarkdown
extra-packages: any::rcmdcheck, XML, XLConnect

# Pour macos, qqs installation supplémentaires
- name: Build site
run: install.packages('textshaping')
shell: Rscript {0}
if: ${{ runner.os == 'macOS' && matrix.r == 'devel' }}

# Pour macos, qqs installation supplémentaires

- name: Build site
run: install.packages('systemfonts')
shell: Rscript {0}
if: ${{ runner.os == 'macOS' && matrix.r == '3.6.1' }}

- uses: r-lib/actions/setup-tinytex@v2

- uses: r-lib/actions/check-r-package@v2
32 changes: 32 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: lint

jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::lintr, local::.
needs: lint

- name: Lint
run: lintr::lint_package()
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
8 changes: 8 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
linters: linters_with_defaults(
object_name_linter = NULL,
cyclocomp_linter = NULL,
line_length_linter = NULL,
commented_code_linter = NULL,
indentation_linter(indent = 4L)
)
encoding: "UTF-8"
4 changes: 3 additions & 1 deletion JDCruncheR.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Version: 1.0

RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default
AlwaysSaveHistory: No

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
Expand All @@ -19,3 +19,5 @@ BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace

UseNativePipeOperator: Yes
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
% Latest JDCruncheR news

# JDCruncheR development

* Update readme
* resolve a bug

---

# JDCruncheR 0.2.4

* The functions' help pages as well as the package vignettes are now available both in French and English.
Expand Down
93 changes: 56 additions & 37 deletions R/Cruncher.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,60 @@ NULL
cruncher <- function(workspace = workspace,
cruncher_bin_directory = getOption("cruncher_bin_directory"),
param_file_path, log_file) {
if (missing(workspace) || is.null(workspace))
if (missing(workspace) || is.null(workspace)) {
stop("Please call the cruncher() on a valid workspace")
}

if (length(workspace) == 0)
if (length(workspace) == 0) {
stop("The first argument must be a non-null workspace path")
}

if (length(workspace) > 1)
if (length(workspace) > 1) {
stop("Please specify only one workspace path")
}

# The path to the workspace must be "whole", not relative/from the setwd.
workspace <- normalizePath(workspace, mustWork = FALSE)
workspace <- sub("\\.xml$", "", workspace) # To remove the .xml from the workspace name, if needed

if (missing(param_file_path) || is.null(param_file_path)) {
param_file_path <- list.files(path = workspace,
recursive = TRUE,
pattern = "\\.params$",
full.names = TRUE)
if (length(param_file_path) != 0)
param_file_path <- list.files(
path = workspace,
recursive = TRUE,
pattern = "\\.params$",
full.names = TRUE
)
if (length(param_file_path) != 0) {
stop("No or more than one .param file was found")
}
}
workspace <- paste0(workspace, ".xml")

if (!file.exists(paste0(cruncher_bin_directory, "/jwsacruncher")))
if (!file.exists(paste0(cruncher_bin_directory, "/jwsacruncher"))) {
stop("There is an error in the path to the cruncher bin folder")
if (!file.exists(workspace))
}
if (!file.exists(workspace)) {
stop("There is an error in the path to the workspace")
if (!file.exists(param_file_path))
}
if (!file.exists(param_file_path)) {
stop("There is an error in the path to the .params file")
}

wd <- getwd()
setwd(cruncher_bin_directory)

log <- shell(paste0(

Check warning on line 77 in R/Cruncher.R

View workflow job for this annotation

GitHub Actions / lint

file=R/Cruncher.R,line=77,col=12,[object_usage_linter] no visible global function definition for 'shell'
"jwsacruncher \""
, workspace
, "\" -x \""
, param_file_path, "\""
"jwsacruncher \"",
workspace,
"\" -x \"",
param_file_path, "\""
), intern = TRUE)

setwd(wd)

if (!missing(log_file) && !is.null(log_file))
if (!missing(log_file) && !is.null(log_file)) {
writeLines(text = log, con = log_file)
}

return(invisible(workspace))
}
Expand Down Expand Up @@ -131,45 +141,47 @@ cruncher_and_param <- function(workspace = workspace,
delete_existing_file = NULL,
log_file = NULL,
...) {

dossier_temp <- tempdir()
fichier_param <- create_param_file(dossier_temp, output = output, ...)
workspace <- cruncher(workspace = workspace, cruncher_bin_directory = cruncher_bin_directory,
param_file_path = fichier_param, log_file = log_file)
workspace <- cruncher(
workspace = workspace, cruncher_bin_directory = cruncher_bin_directory,
param_file_path = fichier_param, log_file = log_file
)

if (rename_multi_documents) {
if (is.null(output))
if (is.null(output)) {
output <- paste0(sub("\\.xml", "", workspace), "\\Output")
}

noms_multi_documents <- multiprocessing_names(workspace)
if (nrow(noms_multi_documents) == 0)
if (nrow(noms_multi_documents) == 0) {
stop("There is no multiprocessing in the workspace!")
}
noms_multi_documents$name <- paste0(output, "\\", noms_multi_documents$name)
noms_multi_documents$file <- paste0(output, "\\", noms_multi_documents$file)
noms_multi_documents <- noms_multi_documents[noms_multi_documents$name != noms_multi_documents$file, ]

if (any(file.exists(noms_multi_documents$name))) {

if (is.null(delete_existing_file)) {
message <- paste("There is already at least one file in ", output, ".\nDo you want to clear the output folder?")
delete_existing_file <- utils::winDialog(type = c("yesnocancel"),
message)
delete_existing_file <- utils::winDialog(
type = c("yesnocancel"),
message
)

delete_existing_file <- isTRUE(delete_existing_file == "YES")

}
if (delete_existing_file) {
unlink(noms_multi_documents$name[file.exists(noms_multi_documents$name)],
recursive = TRUE)
recursive = TRUE
)
file.rename(from = noms_multi_documents$file, to = noms_multi_documents$name)
} else {
warning("There were pre-existing files in the output folder: none were removed or renamed.")
}

} else {
file.rename(from = noms_multi_documents$file, to = noms_multi_documents$name)
}

}

return(invisible(workspace))
Expand Down Expand Up @@ -205,22 +217,26 @@ multiprocessing_names <- function(workspace) {
stop("Please call multiprocessing_names() on a valid workspace")
}

if (length(workspace) == 0)
if (length(workspace) == 0) {
stop("The first argument must be a non-null workspace path")
}

if (length(workspace) > 1)
if (length(workspace) > 1) {
stop("Please specify only one workspace path")
}

workspace <- normalizePath(workspace, mustWork = FALSE)
workspace <- paste0(sub("\\.xml$", "", workspace), ".xml")

if (!file.exists(workspace))
if (!file.exists(workspace)) {
stop("The workspace doesn't exist")
}

xml_workspace <- suppressWarnings(XML::xmlParse(workspace, error = function(...) {}))
noms_objets <- XML::xmlToDataFrame(nodes = XML::getNodeSet(
doc = xml_workspace,
path = "//ns2:demetraGenericWorkspace/ns2:items/ns2:item"))
path = "//ns2:demetraGenericWorkspace/ns2:items/ns2:item"
))
noms_multi_documents <- noms_objets[grep("multi-documents", noms_objets$family), ]
noms_multi_documents <- noms_multi_documents[, c("name", "file")]

Expand Down Expand Up @@ -288,12 +304,15 @@ NULL
update_workspace <- function(workspace = workspace,
policy = "parameters",
cruncher_bin_directory = getOption("cruncher_bin_directory")) {

dossier_temp <- tempdir()
fichier_param <- create_param_file(dossier_temp, output = dossier_temp, policy = policy,
matrix_item = NULL, tsmatrix_series = NULL)
workspace <- cruncher(workspace = workspace, cruncher_bin_directory = cruncher_bin_directory,
param_file_path = fichier_param)
fichier_param <- create_param_file(dossier_temp,
output = dossier_temp, policy = policy,
matrix_item = NULL, tsmatrix_series = NULL
)
workspace <- cruncher(
workspace = workspace, cruncher_bin_directory = cruncher_bin_directory,
param_file_path = fichier_param
)

return(invisible(workspace))
}
Loading

0 comments on commit afced6d

Please sign in to comment.