Not able to execute RScript

I am new to R and want some help to execute .R script.
I have saved a test.R script in Documents folder on my windows machine.
Need some help for step by step execution of the script using Rterm.

Below is the error that I get when I try to execute the script. I have already set the directory in Rterm.

Rscript test.R
Error: unexpected symbol in "Rscript test.R"

This is usually caused by code with punctuation errors, such as failing to close a “quotation mark. Can’t say where, of course without seeing the code.

Thanks. Below is the code

> myString <- "Hello"
> print(myString)

Can you tell us exactly how you tried to execute the script?

This is in RTerm

getwd()
[1] "C:/Users/admin/Documents"
Rscript test.R
Error: unexpected symbol in "Rscript test.R"

This command is meant to be run from a system terminal, not an R console.

I think you are trying to use an R console (what you get by running Rterm) as if it was a system terminal and that is not possible. If you want to execute an .R file from an R console use the source() function.

How do I run it from system terminal. Do I have to run it on command prompt, if yes how ?

Also I did use the source function but that is also giving an error.

source("test.R")
Error in source("test.R") : test.R:1:1: unexpected '>'
1: >
^

You can use the terminal pane next to the console pane.

You have command prompts in your code i. e. ">", those are a console artifact, you shouldn't include them in your code. It should look like this:

myString <- "Hello"
print(myString)

can you please provide more details

https://support.posit.co/hc/en-us/articles/115010737148-Using-the-RStudio-Terminal-in-the-RStudio-IDE#:~:text=The%20RStudio%20terminal%20provides%20access,line-editing%20and%20shell%20history.


This is what I see when I open RStudio. Am I missing anything ?

That is not RStudio, that is the R GUI and you are typing commands in an R console so you can't use Rscript there.

This topic was automatically closed 21 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.