Call a unix program from an R function

invitro.cals ← function(string, flag, string2, string3)
{
	# string is the directory location of all the files to be used
	# string2 is the directory location of all the files if a radionuclide is being modeled
	# string3 is the spine data to be used for the bone marrow sample calculation (see 22)
	print("flag:", quote = FALSE)
	print(flag)
	thalf <- scan(paste(string, "std.decay.time", sep = ""))
	filename <- paste(string, "decay.time", sep = "")
	if(unix(paste("test_file", filename), output = F)) {                     # Here is the call to the program

		thalf.model <- scan(paste(string, "decay.time", sep = ""))
	}
	else {
		thalf.model <- scan(paste(string, "std.decay.time", sep = ""))
	}
	if((flag == 0) || (flag == 5) || (flag == 10) || (flag == 15)) {
	  filename <- paste(string, "counts.blood", sep = "")
	     if(unix(paste("test_file", filename), output = F)) {
                            starter.file <- dget(paste(string, "counts.blood", sep = ""))
                            flag.invitro <- 1
	     }
	    else { ….
             }
    }   …..

Transcript

Now, we can also call unix programs from an R function. So, in this case, we are writing in R, and at this point, we're going to invoke unix passing it this information: "test_file", filename.  We now give it the data that we're going to process - which we scanned in from this array.  If that is true, then we execute this, otherwise, if it is false, then we take the data from this other file, and we put it into the data frame.  So we're looking at if that's true, we use this data frame; otherwise, we get our data and will put it into our data frame.  We can do that many times. We can do if else's, etc. around it.  So the result here is we see that it's very straightforward to call any unix program we want from inside of an R function.