{"id":25352082,"url":"https://github.com/stats4sd/laravel-r-setup","last_synced_at":"2025-10-29T20:31:19.465Z","repository":{"id":57059227,"uuid":"355607234","full_name":"stats4sd/laravel-r-setup","owner":"stats4sd","description":"A helper package to easily setup an R project inside your Laravel application","archived":false,"fork":false,"pushed_at":"2023-10-02T08:37:12.000Z","size":27,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-13T09:47:32.190Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stats4sd.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-04-07T16:08:52.000Z","updated_at":"2023-02-24T06:56:25.000Z","dependencies_parsed_at":"2023-01-30T00:16:02.848Z","dependency_job_id":null,"html_url":"https://github.com/stats4sd/laravel-r-setup","commit_stats":{"total_commits":12,"total_committers":3,"mean_commits":4.0,"dds":"0.41666666666666663","last_synced_commit":"c134fa9c9aa3e26d7d63798e2c9792e339b29ac7"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stats4sd%2Flaravel-r-setup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stats4sd%2Flaravel-r-setup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stats4sd%2Flaravel-r-setup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stats4sd%2Flaravel-r-setup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stats4sd","download_url":"https://codeload.github.com/stats4sd/laravel-r-setup/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238889680,"owners_count":19547658,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-14T18:26:35.907Z","updated_at":"2025-10-29T20:31:19.453Z","avatar_url":"https://github.com/stats4sd.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e [!WARNING]  \n\u003e This repo was intended as a quick way for a Laravel developer to add a template R package in a subfolder. Internally, we have moved in the direction of using submodules, as usually different people are working on the R project vs the Laravel project. As such, this repo is no longer used, as instead we setup a separate R repo, then bring it in as a submodule to the Laravel app when needed.\n\n\n\n# Laravel R Setup\n\nThis helper package can be used to quickly scaffold an R project within the main Laravel project.\n\nOften, we have found the need to pass particular tasks out to R, for example advanced data processing, statistical analysis, or generation of customisable reports through RMarkdown. In these cases, we want to initialise an R project within a sub-folder of the main Laravel application. \n\n## Requirements\nTo use this package locally, you must have R installed, and you should have installed the renv library locally (`install.packages('renv')` in R).\n\n\u003e NOTE: This package does not help with installing R on your local development machine, OR on the server you deploy to. You should handle that separately! \n\n\n\n## Quick Start\n\nTo get started: \n\n1. require the package as a dev dependency: `composer require stats4sd/laravel-r-setup --dev`.\n2. Run the setup script: \n    - If you want to write RMarkdown documents, run `php artisan rsetup rmarkdown`. \n    - If you want a simpler R environment, run `php artisan rsetup r`.\n    \nThis will create a new RStudio project with some example files in `scripts/R`. \n\n## Default R Setup:\nThe 'default' setup creates for you: \n - **An `init.R` script**: This connects R to the same .env file that Laravel uses, and adds a function to connect to the Laravel database.\n - **An `example.R` script**: This provides an example to show how to connect to the database in your scripts. It also acts as a quick test to ensure the setup is working. \n \nIt also initialises [Renv](https://rstudio.github.io/renv/articles/renv.html) - this tool is the R equivalent to composer or npm, and it's recommended to use this to let you quickly setup any required R pacakages when you deploy your application.\n \nYou can run this `example.R` script to test your setup. If it is working, a `user-test.csv` file will be created, containing a list of users in your Laravel application database.\n\n## RMarkdown\nThe rmarkdown option gives you some additional files: \n - **A `example-markdown.R` script**: This demonstrates how you can get data from the Laravel database and pass it to a .Rmd file as a parameter. Run this script to generate a pdf output that contains a list of the current users in your Laravel database. \n - **A `example-markdown.Rmd` file**: This is used together with the example script.\n\n\u003e NOTE: If you intend to produce PDF documents with RMarkdown, you will need to ensure your deployment environment has pdflatex and pandoc installed. You also need to tell R where these applications are located, especially when running R scripts from PHP via Symfony Process.\n\u003e \n\u003e We have found a reliable way is to add the following variables to your .env file, and reference them where needed in your R script:\n\u003e  - RSTUDIO_PANDOC \n\u003e  - PDFLATEX_PATH \n\u003e \n\u003e Our `init.R` script for r-markdown references the PDFLATEX_PATH variable. The RSTUDIO_PANDOC one is a default variable that RMarkdown references when looking for a version of pandoc to use. \n\n\n## How to find your env variables\n\n#### RSTUDIO_PANDOC\n - If you have RStudio installed, open it and run `Sys.getenv(\"RSTUDIO_PANDOC\")`. \n - If you do not, or if you are deploying to a server, ensure you have installed pandoc. Then run:\n    - (for windows - Powershell): `where.exe pandoc`\n    - (for Mac / Linux - Bash): `which pandoc`\n    \nUse the *exact* output in your .env file (include the 'pandoc' on the end of the file path).\n\nExample (from MacOS)\n```\nRSTUDIO_PANDOC=/Applications/RStudio.app/Contents/MacOS/pandoc\n```\n\n\n#### PDFLATEX_PATH\n - Ensure you have pdflatex installed. Then run:\n    - (for windows - Powershell): `where.exe pdflatex`\n    - (for Mac / Linux - Bash): `which pdflatex`\n\nUse the resulting file pathway *without* the pdflatex. You want the path to the executable, not the executable itself. \n\nExample (from MacOS)\n```\nPDFLATEX_PATH=/Library/TeX/texbin/\n```\n\n## Deploying Your Application\nWhen you deploy your Laravel application with R to the server, you will need to add some additional scripts to setup the R environment. It is recommended to use Renv, which is setup automatically when you run `php artisan rsetup r`. \n\n- During development of your R scripts, make sure you run `renv::snapshot()` after installing packages. This will update a `renv.lock` file.\n- Make sure you install R onto your server (or where-ever you are deploying your application). Follow the instructions for your OS. For example, [here](https://linuxize.com/post/how-to-install-r-on-ubuntu-20-04/) is a guide for installing R on Ubuntu 20.04. \n- If you use RMarkdown, you also need to install Pandoc (full instructions [here](https://pandoc.org/installing.html#linux), and maybe a pdf renderer like TexLive. \n- You also need to add the correct .env variables.\n- In your deployment script, add `cd scripts/R \u0026\u0026 Rscript -e \"renv::restore()\"`. You can do this at anytime, but I usually put it just after `npm install`.\n\n\n\n## License\n\nThis repo is covered by an [MIT License (MIT)](LICENCE.md). You are free to copy, use, modify and distribute this package, and it would be lovely if you would credit Stats4SD where-ever you use it. \n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstats4sd%2Flaravel-r-setup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstats4sd%2Flaravel-r-setup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstats4sd%2Flaravel-r-setup/lists"}