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?
Well the host name is typically available as an environment variable:
…But perhaps it would be cleaner to add a custom environment variable when you start R:
Then get that env variable from your script: