Frequently Asked Questions about R
This page contains previously asked questions and answers about R and RStudio. The questions are sorted by topic.
- Is it possible to delete parts of the codes and output in the console? (as it may sometimes include a lot of errors and you have to scroll way back to see previous things)
As far as I am aware, you can only clear your entire console (with the broom). Clearing just some parts of the console is also not necessary, as you will not be sharing output from your R console with anyone. Instead, you can share your script with others and save important results in other files.
- Sometimes R gives warning messages, but it still gives results as well. What should we do with this?
A lot of times, warning messages are informative, but you do not have to do something with it. For now, read the warning messages, but ignore them when output is still produced. When you see an error message, then you have to take action though.
- When running a certain code, R does not give me output yet. Instead, a + sign is given in the R console.
When you see a + sign in the R console, then R is still waiting for you to close the command. Most probably, you forgot a ")" (bracket) somewhere.
- After loading a new package, R tells me that a certain object is masked from another package. What does this mean?
Some objects are included in several packages. For example, the function alpha() is included in both 'ggplot2' and 'psych'. The functions are not the same though. Loading 'psych' after loading 'ggplot' will give you the warning that alpha is masked from the ggplot2 package. In this case, if you are using the function alpha(), you will use the function from the psych package (as the one from the ggplot2 package is masked).
- The package "haven" is not loading when I use the function load("haven"). Why not?
For loading a package, please use library(haven) instead of load(“haven”). Then it will work.
- Importing an SPSS data set does not work for me anymore. It worked fine before, but now it does not. The error message that is given is something like “could not find the function read_spss()”
When an error message refers to a function that is not found, you most probably haven’t installed or loaded a package correctly.
- After not using R for some time, I forgot all the commands in R. Is that a problem?
No it is not. We do not expect you to know all commands by heart (I do not know all commands by heart as well…). We just want you to be able to use R. And when using R, you will have to look up codes a lot of times. Either in the PDF file we provide you, or on the internet. This is normal when using R.
Troubleshooting R code
- My code doesn't run and I don't know what went wrong, how do I fix this?
Generally, when code doesn't run, there's a problem that you're overlooking that can be solved quite easily. If you haven't already done so, try any of the following things to make sure your code is correct.
1. Check the capitalization and correct spelling of commands, functions and
2. Check your bracket use, pipes (%>%), and other methods to string multiple
commands or functions together.
3. Check if you have installed (install.packages) and loaded (library) the correct
- I have checked all this, and a fellow student went over my code as well but it still doesn't work. What do I do now? Additional steps you could take to troubleshoot your code are:
1. By using ?function to see if the explanation of the function shows a difference to
how you've been writing your code.
2. You could use ??searchterms to see if R knows anything about your code.
3. Ask fellow students to help you out, or contact the R helpdesk or ICT Service
4. There are some online resources too for asking questions, such as stackoverflow
and community.rstudio.com. Most of the time you might actually find answers
given on those sites when you research your problem using a search engine.