Loop not working, maybe due to Package ‘grid’ is not available (for R version 3.1.2) but I am using R studio Version 1.0.153?


#1

Hi I am new to R, could I ask a question? Thanks, I get a warning: package ‘grid’ is not available (for R version 3.1.2) but I am using R studio Version 1.0.153? I do have R 3.1.1 on my computer. As I am using R on my work computer, it may take a while to get permission to update R.

Also there are 2 warnings about, warning:package ‘gridExtra’ was built under R version 3.1.3 , warning: package ‘ggplot2’ was built under R version 3.1.3

-update:
The real issue is, a loop is not working, I want to get 3 results of the 3 groups, say age=1,2,3, I just get the last group, age=3. I guess is it due to grid not installed, but may also due to the loop itself....the related code are as below:

DFnew$age = factor(DFnew$age,levels = c("Young","Middle","Senior "))

for (var1 in somegroups))
{
p[[var1]] <- ggplot(data = newDF,
aes(x=time, y=valueOFvar1, shape=90% percentile,col = age)) +...some formatting))
...
}
print(p[[var1]])

Thanks very much,


#2

Hi,
RStudio is an IDE that exists on top of R. The warnings are just warnings, with the exception of the grid warning, which sounds like you need to update your version of R if you want to use it.

There's a really nice, quick explanation of the difference between R and RStudio at the link below, and it also has the links to where you can download an updated version of R.


Reflections on RStudio transparency
#3

Thank you very much Mara, those links are helpful. I just updated my question...it is actually about a loop not working, I thought due to the package issue...

still, thanks very much for reply!


#4

Your code as is cannot be run because it is incomplete. You should make a reprex that runs even if it does produce errors. You may have to modify and reduce you application code to make an example that we can run.You should also show what result you expected. Here is an example of the general structure you could use:

# reduce your code to just enough 
# the problem
#
#all the variables needed to run lookp
a = 1:5
b = 0
# loop, probably a reduced version of what 
# is in your application

for(i in a) {
    b = b + i
}
# show result
b
#> [1] 15
# expected b to be 30 at end of loop
expected_b = 30
# test that checks to see if b is what you expected
identical(b, expected_b)
#> [1] FALSE

Created on 2018-03-26 by the reprex package (v0.2.0).

Here is some info about reprex's. If you have any problems making reprex's work please come back here and we will help you get things going. Note that reprex's are useful not just for questions but for development too.

A prose description isn't sufficient, you also need to make a simple reprex that:

  1. Builds the input data you are using.
  2. The function you are trying to write, even if it doesn't work.
  3. Usage of the function you are trying to write, even if it doesn't work.
  4. Builds the output data you want the function to produce.

You can learn more about reprex's here:

Right now the is an issue with the version of reprex that is in CRAN so you should download it directly from github.

Until CRAN catches up with the latest version install reprex with

devtools::install_github("tidyverse/reprex")

if this gives you an error saying that devtools is not available then use

install.packages("devtools")

and try again.

The reason we ask for a reprex is that it is the easiest and quickest way for someone to understand the issue you are running into and answer it.

Nearly everyone here who is answering questions is doing it on their own time and really appreciate anything you can do to minimize that time.


#5

Your R version is more than 3.5 years old. It's asking for an update :slight_smile: