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

  • SEARCH
  • Home
  • 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 8406469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:07:07+00:00 2026-06-09T23:07:07+00:00

I would like to make R a little bit easier to execute system command.

  • 0

I would like to make R a little bit easier to execute system command. Something like ipython vs python. Here are some thoughts:

  • Define cd function to change working directory by wrapping up the getwd and setwd
  • Define an operator to wrap up the system() command so that I can run something like “$ls” to replace the system(“ls”)

The first one is easy to accomplish. However, I am stuck with the second one. I found no ways to redefine an operator in R for a string. Then I took a step back, I tried to define a sys(param). But now, I still need to input the quotation marks. e.g. I need to run sys(“ls”) instead of sys(ls) to list the directory. Is there a way to make the parameter assume it is a string even without the quotation marks? Thanks. Any suggestions are welcome.

  • 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-09T23:07:08+00:00Added an answer on June 9, 2026 at 11:07 pm

    Updated to simplify functions (remove a regexp) and add support for character input

    You can use match.call inside a function so that you can call the function without using quotation marks like this.

    sys <- function(...) {
      command <- match.call()[[2L]]
      if (!is.character(command)) {
        command <- gsub("- ", "-", deparse(command))
      }
      system(command)
    }
    

    Now, either of the following are equivalent to system("ls -a")

    sys("ls -a")
    sys(ls -a)
    

    The sys function above extracts the second component of the call which is the stuff between the parentheses. i.e. ls -a or "ls -a" in these examples. It then passes that to system (through deparse first if it is not character)

    [I added support for strings because otherwise it doesn’t work with forward slashes, dots, etc. For example, sys(ls /home) does not work, but sys("ls /home") does.]

    However, this still requires using parentheses 🙁


    To avoid the use of parentheses, you can mask an operator. In the initial version of this answer, I showed how to mask ! which is not a good a idea. You suggested using ? in the comments which could be done like this.

    `?` <- function(...) {
      command <- match.call()[[2L]]
      if (!is.character(command)) {
        command <- gsub("- ", "-", deparse(command))
      }
      system(command)
    } 
    

    Now, this is the same as system("ls -a -l")

    ?ls -a -l
    

    But, if you need to use forward slashes, you’d have to use quotes like this

    ?"ls /home"
    

    Alternatively, you could create a special binary operator

    "%sys%" <- function(...) {
      system(sub("%sys%", "", deparse(match.call())))
    }
    

    You can use it like this

    ls %sys% -l
    ls %sys% .
    

    If you need to use forward slashes, you have to quote the right side

    ls %sys% "/home"
    

    A downside is that it requires exactly one argument on the right side of the operator.

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

Sidebar

Related Questions

I would like to make a system of page on android 3.0 a little
I would like to do just a little bit of extra logic in rotues.rb,
can you help me a little bit with the Terminal? i would like to
I've got a CodePen here where I'm trying to make my little 8-bit dude
I'm trying to make life a little bit easier for me. I get a
I would like make a script using PHP (probably need JS) to send POST
I would like make an extension method for the generic class A which takes
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to make sure my classes are robust - even if they
I would like to make a password and username entry field. And a submit

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.