I cant re assign value in my Rstudio

Hi, i am literally just starting to learn R using R studio yesterday by watching some course online.
If this is not the place to post it, please let me know. i ll take it down.

I dont know how to state it in this forum, so here goes nothing:

  1. Open RStudio
  2. New script, i type i <- 1 and run it, ctrl +enter
  3. It populates the env pane on the right corner.
  4. But then i delete the environment, using the broom icon.
  5. When i rerun the same thing i <-1 it does not populates the environment
  6. i tried creating new r script, i does not work either.

Question is:

  1. Am i not supposed to delete the env ?
  2. Since i am learning, i tend to watch and do what i saw, learning by doing, this encourages me to delete the environment when i see a specific stuff online.
  3. How can i reassign the value of 1 to "i" or anything that i want after deleting the environment.

Side note:

  1. Using windows 11
  2. chatgpt said:

If you want to see the value of i in the "Environment" pane in RStudio, it won't appear automatically since you've cleared the environment. However, you can use the ls() function to list the objects in your environment and the print(i) command to display the value of i in the console.

i tried both, and also restarting the session, nothing happened

  1. What i am learning is the while function
i <- 1 
while(i < 25 ) {       
  print(i)
  i <- i + 1
}

Thank you

I could not duplicate the condition.

  1. When working in RStudio I frequently restart R by using Ctrl+Shift+F10; That clears the environment.
  2. Okay.
  3. See my example
  4. Avoid ChatGPT to answer these questions; it may or may not be correct, and chances are that it will be incorrect.
# assign the value 1 to i
i <- 1

# list objects
ls()
#> [1] "i"

# while ...
while(i < 10){
  print(i)
  i <- i + 1
}
#> [1] 1
#> [1] 2
#> [1] 3
#> [1] 4
#> [1] 5
#> [1] 6
#> [1] 7
#> [1] 8
#> [1] 9

# remove objects from the environment
rm(list = ls())

# list objects
ls()
#> character(0)

# assign the value 1 to i
i <- 1

# list objects
ls()
#> [1] "i"

Created on 2023-08-16 with reprex v2.0.2

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.