Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix make setup #155

Open
hannesdatta opened this issue Sep 26, 2023 · 2 comments
Open

fix make setup #155

hannesdatta opened this issue Sep 26, 2023 · 2 comments

Comments

@hannesdatta
Copy link
Owner

this year, students experienced a lot of troubles getting make installed. although the instructions are correct, half of the class wasn't ready in week 5 to execute make code or launch R from the command prompt.

a few options:

  • remind students about it in earlier lectures
  • offer some way for students to "check" their configuration
@hannesdatta
Copy link
Owner Author

Maybe a 'python' script that checks stuff?

@hannesdatta
Copy link
Owner Author

User
Can you write a Python script that does a few checks on the computer it runs. In particular, I want the script to check (and individually report) on 


- whether R is installed (and which version)
- whether R can be executed from the command prompt/terminal using Rscript 
- whether packages can be installed in R
- whether python is installed
- whether anaconda / conda is installed
- whether the computer can use make (for automation, it's a tool called `make`)
- whether R can knit RMarkdown documents
- whether git is installed
- whether git can push and pull (i.e., whether authentication is done correctly)

Creating a script to check all the points you've listed requires calling external commands from Python and checking for their existence and results. Here's a basic example for each:

import subprocess
import os

def check_command(cmd, expected_in_output=None):
    try:
        output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True, universal_newlines=True)
        if expected_in_output:
            return expected_in_output in output
        else:
            return True
    except subprocess.CalledProcessError as e:
        return False
    except Exception as e:
        print(f"Error running command {cmd}: {e}")
        return False

def main():
    # Check if R is installed and its version
    if check_command("R --version"):
        print("R is installed.")
        version = subprocess.check_output("R --version", shell=True).decode('utf-8').split('\n')[0]
        print(version)
    else:
        print("R is not installed.")
    
    # Check if Rscript can be executed
    if check_command("Rscript -e 'print(1+1)'", "2"):
        print("Rscript can be executed from the command prompt.")
    else:
        print("Cannot execute Rscript from the command prompt.")
    
    # Check if packages can be installed in R
    if check_command("R -e 'install.packages(\"dplyr\", repos=\"https://cran.rstudio.com/\")'"):
        print("Packages can be installed in R.")
    else:
        print("Packages cannot be installed in R.")
    
    # Check if Python is installed
    if check_command("python --version"):
        print("Python is installed.")
    else:
        print("Python is not installed.")
    
    # Check if Anaconda/conda is installed
    if check_command("conda --version"):
        print("Anaconda/conda is installed.")
    else:
        print("Anaconda/conda is not installed.")
    
    # Check if 'make' can be used
    if check_command("make --version"):
        print("'make' tool is available.")
    else:
        print("'make' tool is not available.")
    
    # Check if R can knit RMarkdown documents
    if check_command("R -e 'rmarkdown::render(\"example.Rmd\")'", "output file: example.html"):
        print("R can knit RMarkdown documents.")
    else:
        print("R cannot knit RMarkdown documents.")
    
    # Check if git is installed
    if check_command("git --version"):
        print("Git is installed.")
    else:
        print("Git is not installed.")
    
    # Check if git can push and pull might require an actual repository and action. 
    # I'll leave a note about this.
    print("Note: Checking if git can push and pull requires an actual repository and action. Manual check recommended.")

if __name__ == "__main__":
    main()

Note:

  • For the git push and pull check, it's tricky. It depends on which repository you're dealing with, your permissions on that repository, and the authentication mechanism in place (SSH key, access token, username & password). You'd need to manually check this or set up a specific scenario to test it.

  • To check if R can knit RMarkdown documents, the script assumes you have a document called example.Rmd in the directory you're running the script from. Ensure this or adjust the filename accordingly.

  • Checking if packages can be installed in R might actually install the package. If you just want to check and not install, you'd need a more sophisticated check.

Please be aware that executing this script may make changes to your system (like installing an R package). Adjust the commands accordingly based on your needs. Always backup your data and understand the implications of running scripts that interact with system commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant