Skip to content

Commit feaa4f1

Browse files
committed
feat-topological_sort
1 parent 4eef1cb commit feaa4f1

File tree

210 files changed

+24023
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+24023
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
* @siriak @acylam @eshom
2+
*.md @Panquesito7
3+
/.github @Panquesito7
4+
LICENSE @Panquesito7
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copilot Instructions for TheAlgorithms/R
2+
3+
## General Guidelines
4+
5+
This repository contains implementations of various algorithms in R. All contributions should follow these guidelines to maintain code quality and consistency.
6+
7+
## Code Quality & Functionality
8+
9+
- Ensure that your code is functional and well-structured before submitting
10+
- The code should run without errors in an R environment and produce the expected output
11+
- Follow best practices for efficiency, readability, and maintainability
12+
- Use consistent and meaningful variable names (use `.` or `_` to separate words, e.g., `results.df` for a data frame)
13+
14+
## Adding New Algorithms
15+
16+
When adding a new algorithm:
17+
- **Verify that the algorithm is not already implemented** in the repository (including under a different name)
18+
- **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)
19+
- Include a brief explanation of the algorithm in the file as comments
20+
- Add an example showcasing its usage (can be commented within the script)
21+
- **Update DIRECTORY.md** to include the new algorithm in the appropriate section
22+
23+
## Modifying Existing Algorithms
24+
25+
When modifying existing algorithms:
26+
- Clearly document the changes in your pull request description
27+
- Ensure that your modifications do not break existing functionality
28+
- If applicable, update or add test cases to validate your changes
29+
30+
## File Naming & Structure Conventions
31+
32+
- **All code file names must use lowercase `.r` extension** (not `.R`)
33+
- Ensure that filenames follow the existing directory structure and naming patterns
34+
- Files should be placed in the appropriate category directory (e.g., `sorting_algorithms/`, `graph_algorithms/`, `mathematics/`)
35+
36+
## Documentation & Comments
37+
38+
- Provide clear and concise documentation in the form of comments within the code
39+
- Add a brief docstring at the beginning of the script explaining:
40+
- What the algorithm does
41+
- The expected input and output
42+
- Any dependencies required
43+
44+
## Testing & Verification
45+
46+
Before submitting a pull request, verify that your code:
47+
- Runs correctly with different test cases
48+
- Does not produce unnecessary warnings or errors
49+
- If applicable, add a test file demonstrating the algorithm's correctness
50+
51+
## Pull Request Review Checklist
52+
53+
When reviewing a pull request:
54+
- Verify that any added algorithms or data structures aren't already implemented elsewhere in the repository (including under a different name)
55+
- 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)
56+
- Check that the extension of all code file names is a lowercase `.r`
57+
- Check that DIRECTORY.md was updated correctly
58+
- Verify that the code includes appropriate documentation and examples
59+
- Ensure that variable naming follows repository conventions
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Taken from https://stackoverflow.com/a/4749909 and slightly edited. Thanks!
2+
list_dirs <- function(path=".", pattern=NULL, all.dirs=FALSE,
3+
full.names=FALSE, ignore.case=FALSE) {
4+
5+
all <- list.files(path, pattern, all.dirs,
6+
full.names=TRUE, recursive=FALSE, ignore.case)
7+
dirs <- all[file.info(all)$isdir]
8+
9+
if(isTRUE(full.names))
10+
return(dirs)
11+
else
12+
return(basename(dirs))
13+
}
14+
15+
cat("R process started.\n")
16+
cat("Change working directory to documentation directory\n")
17+
setwd("documentation")
18+
19+
cat("Creating the directory list\n")
20+
dirlist <- list_dirs(path="..", pattern=".R", ignore.case = TRUE, full.names = TRUE)
21+
22+
cat("Getting a list of R scripts from the algorithm directories.\n")
23+
scriptlist <- lapply(dirlist, list.files, ".R", ignore.case = TRUE, full.names = TRUE)
24+
cat("Removing from the list empty directories.\n")
25+
scriptlist <- scriptlist[!sapply(scriptlist, identical, character(0))]
26+
print(unlist(scriptlist))
27+
28+
cat("Compiling documentation from scripts.\n")
29+
invisible(lapply(unlist(scriptlist), function(x) tryCatch(knitr::spin(x),
30+
error = function(e) message("Error compiling: ", e))))
31+
32+
cat("R process done.\n")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Directory/Filename Formatter workflow
2+
on: [push, pull_request]
3+
4+
jobs:
5+
main:
6+
name: (Directory) Formatter
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- name: Setup Git configuration
11+
run: |
12+
git config --global user.name 'autoprettier'
13+
git config --global user.email '[email protected]'
14+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
15+
- name: Filename Formatter
16+
run: |
17+
IFS=$'\n'
18+
for fname in `find . -type f -name '*.R' -o -name '*.R'`
19+
do
20+
echo "${fname}"
21+
new_fname=`echo ${fname} | tr ' ' '_'`
22+
echo " ${new_fname}"
23+
new_fname=`echo ${new_fname} | tr 'A-Z' 'a-z'`
24+
echo " ${new_fname}"
25+
new_fname=`echo ${new_fname} | tr '-' '_'`
26+
echo " ${new_fname}"
27+
if [ ${fname} != ${new_fname} ]
28+
then
29+
echo " ${fname} --> ${new_fname}"
30+
git "mv" "${fname}" ${new_fname}
31+
fi
32+
done
33+
git commit -am "Formatting filenames ${GITHUB_SHA::8}" || true
34+
- name: Update DIRECTORY.md
35+
run: |
36+
wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/build_directory_md.py
37+
python3 build_directory_md.py R . .R,.r > DIRECTORY.md
38+
git diff
39+
git commit -m "Update DIRECTORY.md" DIRECTORY.md || true
40+
git push --force origin HEAD:$GITHUB_REF || true
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Documentation
2+
on: [push, pull_request]
3+
4+
jobs:
5+
MakeDocs:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v3
9+
- name: Setup R
10+
uses: r-lib/actions/setup-r@v2-branch
11+
with:
12+
r-version: '4.1.0'
13+
- name: Create Documentation directory
14+
run: |
15+
echo "Creating 'Documentation'"
16+
mkdir -p documentation
17+
- name: Install dependencies
18+
run: |
19+
echo "Installing R package dependencies. Scripts might have additional dependencies installed."
20+
Rscript -e 'if (!require(knitr)) install.packages("knitr")'
21+
Rscript -e 'if (!require(markdown)) install.packages("markdown")'
22+
- name: Remove old documentation
23+
run: 'rm -rf documentation/*'
24+
- name: Generate new documentation
25+
run: 'Rscript .github/scripts/doc_builder.r'
26+
- name: Commit Documentation
27+
run: |
28+
git diff-index --quiet HEAD && exit
29+
echo "Setting up Git to push changes."
30+
git config --global user.name 'autoprettier'
31+
git config --global user.email '[email protected]'
32+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
33+
echo "Staging documentation"
34+
git add documentation/ # This is the only directory that has changes and should be staged
35+
git commit -m "Update documentation" || true
36+
git push || true
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: 'Close stale issues and PRs'
2+
on:
3+
schedule:
4+
- cron: '0 0 * * *'
5+
jobs:
6+
stale:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/stale@v4
10+
with:
11+
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.'
12+
close-issue-message: 'This issue was closed because it has been stalled for 7 days with no activity.'
13+
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.'
14+
close-pr-message: 'This PR was closed because it has been stalled for 7 days with no activity.'
15+
exempt-issue-labels: 'dont-close'
16+
exempt-pr-labels: 'dont-close'
17+
days-before-stale: 30
18+
days-before-close: 7
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM gitpod/workspace-full
2+
3+
RUN brew install R

Desktop/open-source/R/.gitpod.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
image:
2+
file: .gitpod.Dockerfile

0 commit comments

Comments
 (0)