Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7847885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:02:07+00:00 2026-06-02T18:02:07+00:00

I have a very basic question. I am a new user of R, these

  • 0

I have a very basic question.

I am a new user of R, these days i am using one R package for my analysis, i have to run list of R commands of that package to get desired output.
I want to make my analysis pipeline and automate it so that i can do my work using one single R command with required parameters.

such type of work we do in shell scripts (where we add number of linux commands, awk/sed/perl lines

please provide me some link on how to do this, i would be thankful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:02:08+00:00Added an answer on June 2, 2026 at 6:02 pm

    Suppose this was my analysis pipeline: I want to generate 10 numbers from the normal distribution with mean MU and standard deviation SD and then do something else with them:

    MU <- 1  # the mean
    SD <- .5 # standard deviation
    NUMBER_TO_GENERATE <- 10
    
    x <- rnorm(NUMBER_TO_GENERATE, mean=MU, sd=SD)
    # ... more analysis here.
    

    At the moment I copy-paste these commands into the R terminal.
    There are a few ways to “automate” this.

    1. Write a function

    I encompass my list of commands to execute into one big function, and put my parameters as function parameters:

    myFunction <- function( MU, SD, NUMBER_TO_GENERATE ) {
        x <- rnorm(NUMBER_TO_GENERATE, mean=MU, sd=SD)
        # ... rest of analysis
    }
    

    Now within R I can just do myFunction(1, .5, 10), reducing the number of commands I have to type to 1.

    2. Write a script

    I could write a script file myScript.r. This is like a bash script except it’s a list of R commands.

    I can either put my original list of commands in there, Or I could put my function in there plus an additional statement at the bottom myFunction(1,.5,10).

    Then from within R, I can do:

    source('myScript.r')
    

    and it will run all the R commands in the script.

    3. From the shell

    If you want to source this script from the shell, I’d suggest having a file myScript.r with the function inside it.

    Then check out Rscript (you can just ?Rscript from within R). This comes installed R by default, and you use it for executing R commands from a unix/windows command line.

    For example:

    [mathematical.coffee@bar ~]$ Rscript -e '1+1'
    [1] 2
    

    In particular, you could combine methods 1) and 2) with Rscript to do something like:

    [mathematical.coffee@bar ~]$ Rscript -e 'source("myScript.R"); myFunction( 1, .5, 10 )'
    

    to run your function.

    Or you could of course just include the myFunction(1, .5, 10) in your myScript.R, in which case you can just do Rscript myScript.R.

    The advantage of the former is if you wanted to do shell scripting (I only mention this because you mentioned bash scripts in your question). In a bash script we could do something like:

    #!/bin/bash
    MU=1;
    SD=.5;
    NUM=10;
    
    Rscript -e "source('myScript.r'); myFunction($MU,$SD,$NUM)"
    

    However I’d argue for not mixing bash scripts with R scripts – as I mentioned before, I only mention this option because you mentioned bash/unix scripts in your question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

quick and very basic newbie question. If i have list of dictionaries looking like
I'm very new to both of these so please forgive my basic question. I
I am new to javascript and have a very basic question: I have this
I'm very new to ruby & Sinatra and I have a basic question: The
I'm very new to performance engineering, so I have a very basic question. I'm
I am new to JavaScript, I have a very basic question. I have this
I'm new to Python and have what is probably a very basic question about
I have a very basic question. Lets take this snippet: #include <stdio.h> void foo(void)
I have a very basic question. Scenario: 2 forms Form1, Form2- Dialog box which
A very basic question in excel. I have a column with valid and with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.