1

I want to execute in Rstudio this powershell command

[System.IO.File]::ReadLines(".\Dropbox\TesisGrado\R_Data\rawdata\5.Azules\200 ppfd\65.dm68i.e.r.1.dat")

I've tried many ways like

system( "[System.IO.File]::ReadLines", input= ".\\65.dm68i.e.r.1.dat")

shell("[System.IO.File]::ReadLines", input= ".\\Dropbox\\TesisGrado\\R_Data\\rawdata\\5.Azules\\200\ ppfd\\65.dm68i.e.r.1.dat")

system("cmd.exe", input = paste("powershell [System.IO.File]::ReadLines(\".\\Dropbox\\TesisGrado\\R_Data\\rawdata\\5.Azules\\200\ ppfd\\65.dm68i.e.r.1.dat\")"))

system("cmd.exe", input = paste("powershell [System.IO.File]::ReadLines(\"65.dm68i.e.r.1.dat\")"))

Getting this kind of error

Microsoft Windows [Versi¢n 10.0.16299.192]
(c) 2017 Microsoft Corporation. Todos los derechos reservados.

    C:\Users\Admin\Dropbox\TesisGrado\R_Data\rawdata\5.Azules\200 ppfd>powershell [System.IO.File]::ReadLines("65.dm68i.e.r.1.dat")
    En l¡nea: 1 Car cter: 29
    + [System.IO.File]::ReadLines(65.dm68i.e.r.1.dat)
    +                             ~
    Falta el par‚ntesis de cierre ')' en la llamada al m‚todo.
    En l¡nea: 1 Car cter: 29
    + [System.IO.File]::ReadLines(65.dm68i.e.r.1.dat)
    +                             ~~~~~~~~~~~~~~~~~~
    Token '65.dm68i.e.r.1.dat' inesperado en la expresi¢n o la instrucci¢n.
    En l¡nea: 1 Car cter: 47
    + [System.IO.File]::ReadLines(65.dm68i.e.r.1.dat)
    +                                               ~
    Token ')' inesperado en la expresi¢n o la instrucci¢n.
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall
     
    
    C:\Users\Admin\Dropbox\TesisGrado\R_Data\rawdata\5.Azules\200 ppfd>[1] 0

My current directory in Rstudio is C:/Users/Admin/Dropbox/TesisGrado/R_Data/rawdata/5.Azules/200 ppfd/

What i'm doing wrong? How can i read that file executing powershell command?

1
  • R's system and system2 do not deal well with arguments that have embedded spaces. I suggest using the ps package. Commented Oct 23, 2021 at 1:19

1 Answer 1

1

In Rstudio, system() works just by specifying the file name, if you are in the directory that contains it. In PowerShell you must specify the full path, no matter if you are in the folder or not. Hence,

system2("cmd.exe", input = paste("powershell [System.IO.File]::ReadLines('.\\65.dm68i.e.r.1.dat')"))

The above code works. I had to change the quotation.

Sign up to request clarification or add additional context in comments.

3 Comments

Your answer is very difficult to understand. I think you should rephrase the first sentence.
Like it now? Thanks
Yeah, Mauro, stackoverflow.com/revisions/69685195/2 is much better. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.