Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Desktop/open-source/R/.github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* @siriak @acylam @eshom
*.md @Panquesito7
/.github @Panquesito7
LICENSE @Panquesito7
59 changes: 59 additions & 0 deletions Desktop/open-source/R/.github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copilot Instructions for TheAlgorithms/R

## General Guidelines

This repository contains implementations of various algorithms in R. All contributions should follow these guidelines to maintain code quality and consistency.

## Code Quality & Functionality

- Ensure that your code is functional and well-structured before submitting
- The code should run without errors in an R environment and produce the expected output
- Follow best practices for efficiency, readability, and maintainability
- Use consistent and meaningful variable names (use `.` or `_` to separate words, e.g., `results.df` for a data frame)

## Adding New Algorithms

When adding a new algorithm:
- **Verify that the algorithm is not already implemented** in the repository (including under a different name)
- **Confirm that the proposed algorithm is a recognized computer-science algorithm**, not a problem-specific adaptation of a general technique (e.g., tuned for LeetCode or other competitive-programming problems)
- Include a brief explanation of the algorithm in the file as comments
- Add an example showcasing its usage (can be commented within the script)
- **Update DIRECTORY.md** to include the new algorithm in the appropriate section

## Modifying Existing Algorithms

When modifying existing algorithms:
- Clearly document the changes in your pull request description
- Ensure that your modifications do not break existing functionality
- If applicable, update or add test cases to validate your changes

## File Naming & Structure Conventions

- **All code file names must use lowercase `.r` extension** (not `.R`)
- Ensure that filenames follow the existing directory structure and naming patterns
- Files should be placed in the appropriate category directory (e.g., `sorting_algorithms/`, `graph_algorithms/`, `mathematics/`)

## Documentation & Comments

- Provide clear and concise documentation in the form of comments within the code
- Add a brief docstring at the beginning of the script explaining:
- What the algorithm does
- The expected input and output
- Any dependencies required

## Testing & Verification

Before submitting a pull request, verify that your code:
- Runs correctly with different test cases
- Does not produce unnecessary warnings or errors
- If applicable, add a test file demonstrating the algorithm's correctness

## Pull Request Review Checklist

When reviewing a pull request:
- Verify that any added algorithms or data structures aren't already implemented elsewhere in the repository (including under a different name)
- Confirm that the proposed algorithm is a recognized computer-science algorithm, not a problem-specific adaptation of a general technique (e.g., tuned for LeetCode or other competitive-programming problems)
- Check that the extension of all code file names is a lowercase `.r`
- Check that DIRECTORY.md was updated correctly
- Verify that the code includes appropriate documentation and examples
- Ensure that variable naming follows repository conventions
32 changes: 32 additions & 0 deletions Desktop/open-source/R/.github/scripts/doc_builder.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Taken from https://stackoverflow.com/a/4749909 and slightly edited. Thanks!
list_dirs <- function(path=".", pattern=NULL, all.dirs=FALSE,
full.names=FALSE, ignore.case=FALSE) {

all <- list.files(path, pattern, all.dirs,
full.names=TRUE, recursive=FALSE, ignore.case)
dirs <- all[file.info(all)$isdir]

if(isTRUE(full.names))
return(dirs)
else
return(basename(dirs))
}

cat("R process started.\n")
cat("Change working directory to documentation directory\n")
setwd("documentation")

cat("Creating the directory list\n")
dirlist <- list_dirs(path="..", pattern=".R", ignore.case = TRUE, full.names = TRUE)

cat("Getting a list of R scripts from the algorithm directories.\n")
scriptlist <- lapply(dirlist, list.files, ".R", ignore.case = TRUE, full.names = TRUE)
cat("Removing from the list empty directories.\n")
scriptlist <- scriptlist[!sapply(scriptlist, identical, character(0))]
print(unlist(scriptlist))

cat("Compiling documentation from scripts.\n")
invisible(lapply(unlist(scriptlist), function(x) tryCatch(knitr::spin(x),
error = function(e) message("Error compiling: ", e))))

cat("R process done.\n")
40 changes: 40 additions & 0 deletions Desktop/open-source/R/.github/workflows/directory_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Directory/Filename Formatter workflow
on: [push, pull_request]

jobs:
main:
name: (Directory) Formatter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Git configuration
run: |
git config --global user.name 'autoprettier'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
- name: Filename Formatter
run: |
IFS=$'\n'
for fname in `find . -type f -name '*.R' -o -name '*.R'`
do
echo "${fname}"
new_fname=`echo ${fname} | tr ' ' '_'`
echo " ${new_fname}"
new_fname=`echo ${new_fname} | tr 'A-Z' 'a-z'`
echo " ${new_fname}"
new_fname=`echo ${new_fname} | tr '-' '_'`
echo " ${new_fname}"
if [ ${fname} != ${new_fname} ]
then
echo " ${fname} --> ${new_fname}"
git "mv" "${fname}" ${new_fname}
fi
done
git commit -am "Formatting filenames ${GITHUB_SHA::8}" || true
- name: Update DIRECTORY.md
run: |
wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/build_directory_md.py
python3 build_directory_md.py R . .R,.r > DIRECTORY.md
git diff
git commit -m "Update DIRECTORY.md" DIRECTORY.md || true
git push --force origin HEAD:$GITHUB_REF || true
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Documentation
on: [push, pull_request]

jobs:
MakeDocs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup R
uses: r-lib/actions/setup-r@v2-branch
with:
r-version: '4.1.0'
- name: Create Documentation directory
run: |
echo "Creating 'Documentation'"
mkdir -p documentation
- name: Install dependencies
run: |
echo "Installing R package dependencies. Scripts might have additional dependencies installed."
Rscript -e 'if (!require(knitr)) install.packages("knitr")'
Rscript -e 'if (!require(markdown)) install.packages("markdown")'
- name: Remove old documentation
run: 'rm -rf documentation/*'
- name: Generate new documentation
run: 'Rscript .github/scripts/doc_builder.r'
- name: Commit Documentation
run: |
git diff-index --quiet HEAD && exit
echo "Setting up Git to push changes."
git config --global user.name 'autoprettier'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
echo "Staging documentation"
git add documentation/ # This is the only directory that has changes and should be staged
git commit -m "Update documentation" || true
git push || true
18 changes: 18 additions & 0 deletions Desktop/open-source/R/.github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 'Close stale issues and PRs'
on:
schedule:
- cron: '0 0 * * *'
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v4
with:
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.'
close-issue-message: 'This issue was closed because it has been stalled for 7 days with no activity.'
stale-pr-message: 'This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.'
close-pr-message: 'This PR was closed because it has been stalled for 7 days with no activity.'
exempt-issue-labels: 'dont-close'
exempt-pr-labels: 'dont-close'
days-before-stale: 30
days-before-close: 7
3 changes: 3 additions & 0 deletions Desktop/open-source/R/.gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM gitpod/workspace-full

RUN brew install R
2 changes: 2 additions & 0 deletions Desktop/open-source/R/.gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
image:
file: .gitpod.Dockerfile
Loading