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 7167521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:35:36+00:00 2026-05-28T14:35:36+00:00

I am developing R code that needs to run redundantly on two servers. Some

  • 0

I am developing R code that needs to run redundantly on two servers. Some aspects of the code (like file paths or error message footers) need to be specific to each server. Rather than have server-specific versions of each file, I would prefer to switch based on the hostname or ip of the machine currently running the code. How do I

I’m picturing something like this

if(localIP == 123.45.678.9){
  msg = "Sent by server A"
} else if (localIP == 123.55.555.5) {
  msg = "Sent by server B"
} else {
  msg = "Default message"
}

So, how do I get that localIP value or something similarly identifying?

  • 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-05-28T14:35:37+00:00Added an answer on May 28, 2026 at 2:35 pm

    Well the host name is typically available as an environment variable:

    # Windows: COMPUTERNAME, Linux: HOST or HOSTNAME
    host <- Sys.getenv(c("COMPUTERNAME", "HOST", "HOSTNAME"))
    host <- unname(host[nchar(host)>0][1])
    

    …But perhaps it would be cleaner to add a custom environment variable when you start R:

    R -f myscript.R myserver=A
    

    Then get that env variable from your script:

    server <- Sys.getenv("myserver")
    msg <- switch (server, A="Sent by server A", B="Sent by server B", "Default message")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say that you're developing code which needs to compile and run on multiple hosts
Sometimes for testing/developing purposes we make some changes in the code that must be
I am developing a 3d shooter game that I would like to run on
I'm currently developing a custom control and realize that my code is being run
Hi i'm developing an application which requires me to run some bash code is
I have been developing a small Java utility that uses two frameworks: Encog and
I am developing / maintaining a tool that allows users to run queries against
I'm developing an application that needs to store lots of records in an organized
I am developing a commercial VB.net WPF application that needs user generated scripts for
I am developing a java code that signs documents using a certificate token. So

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.