Isn’t R a language?
You may hear me speak of R in the third person. For example, I might say, “Tell R to do this” or “Tell R to do that”, but of course R can’t do anything; it is just a language. This way of speaking is shorthand for saying, “Tell your computer to do this by writing a command in the R language at the command line of your RStudio console.” Your computer, and not R, does the actual work. Is this shorthand confusing and slightly lazy to use? Yes. Do a lot of people use it? Everyone I know—probably because it is so convenient.
When do we compile?
In some languages, like C, Java, and FORTRAN, you have to com‐ pile your human-readable code into machine-readable code (often 1s and 0s) before you can run it. If you’ve programmed in such a lan‐ guage before, you may wonder whether you have to compile your R code before you can use it. The answer is no. R is a dynamic pro‐ gramming language, which means R automatically interprets your code as you run it.
Cancelling commands
Some R commands may take a long time to run. You can cancel a command once it has begun by typing ctrl + c. Note that it may also take R a long time to cancel the command.
Functions R
\ comes with many functions that you can use to do sophisticated tasks like random sampling. For example, you can round a number with the round function, or calculate its factorial with the factorial function. Using a function is pretty simple. Just write the name of the function and then the data you want the function to operate on in parentheses:
Extract function
RStudio comes with a tool that can help you build functions. To use it, highlight the lines of code in your R script that you want to turn into a function. Then click Code > Extract Function in the menu bar. RStudio will ask you for a function name to use and then wrap you code in a function call. It will scan the code for undefined vari‐ ables and use these as arguments. You may want to double-check RStudio’s work. It assumes that your code is correct, so if it does something surprising, you may have a problem in your code
Currently you visiting in our blog please Subscribe for more information.