Skip to content

Instantly share code, notes, and snippets.

@BroVic
Created September 11, 2022 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BroVic/30bdb14c66e5da9b9ce36d1d552594a3 to your computer and use it in GitHub Desktop.
Save BroVic/30bdb14c66e5da9b9ce36d1d552594a3 to your computer and use it in GitHub Desktop.
A PowerShell script for automating R CMD ... for the naijR package
# Source file: rcmd.ps1
#
# A PowerShell script for batch execution of R specifically
# for the naijR project
# TODO: Affirm script execution policy
[CmdletBinding()]
PARAM (
[ValidateSet('build', 'check')]
[string]$Command = "build",
[string]$pkgname = "naijR",
[string]$opts = $null
)
if ($Command.Equals("build")) {
$opts = "--resave-data"
}
elseif ($Command.Equals("check")) {
# TODO: Add a check for new unbuilt version of
# the source code and build that before checking
$tarext = ".tar.gz"
$wildcard = "_*.9*$tarext"
$pattern = $pkgname + $wildcard
$emptystr = ""
$archs = Get-ChildItem -Filter $pattern |
ForEach-Object {
($_.Name).Replace($tarext, $emptystr)
} |
Sort-Object -Descending
$pkgname = $archs[0] + $tarext
$opts = "--as-cran"
}
& "Rcmd.exe" $Command $opts $pkgname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment