Call R Script from Python with argumentsUsing a Windows path within Python's subprocess (point to an executable) [beginner]Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonHow can I make a time delay in Python?“Least Astonishment” and the Mutable Default ArgumentDoes Python have a string 'contains' substring method?

How can I train a replacement without them knowing?

Why was ramjet fuel used as hydraulic fluid during Saturn V checkout?

Show two plots together: a two dimensional curve tangent to the maxima of a three dimensional plot

Is there a way to make the "o" keypress of other-window <C-x><C-o> repeatable?

Sinc interpolation in spatial domain

Build a mob of suspiciously happy lenny faces ( ͡° ͜ʖ ͡°)

What security risks does exposing the size of the plaintext entail?

Do predators tend to have vertical slit pupils versus horizontal for prey animals?

Linear and Integer programming materials

Peterhead Codes and Ciphers Club: Weekly Challenge

Can I submit a paper computer science conference using an alias if using my real name can cause legal trouble in my original country

Would getting a natural 20 with a penalty still count as a critical hit?

Metal that glows when near pieces of itself

Can 'in-' mean both 'in' and 'no'?

Vegetarian dishes on Russian trains (European part)

Check disk usage of files returned with spaces

When does The Truman Show take place?

Are unaudited server logs admissible in a court of law?

Do banks' profitability really suffer under low interest rates

Did they show Truman doing private things (toilet, etc) when filming him for 24 hours, 7 days a week?

Starships without computers?

Do the eight axioms of vector space imply closure?

Why don't politicians push for fossil fuel reduction by pointing out their scarcity?

Will some rockets really collapse under their own weight?



Call R Script from Python with arguments


Using a Windows path within Python's subprocess (point to an executable) [beginner]Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonHow can I make a time delay in Python?“Least Astonishment” and the Mutable Default ArgumentDoes Python have a string 'contains' substring method?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a r Script with the code:



args = commandArgs(trailingOnly=TRUE)
myData <- read.csv(file=args[0])


I want to run this using a GUI and deliver a choosen csv file with this python code



from tkinter import filedialog
from tkinter import *
import subprocess

window = Tk()
window.geometry('500x200')
window.title("Wordcloud Creator")
lbl = Label(window, text="1. Please prepare a CSV (-Trennzeichen) file with the columns untgscod, berpos, SpezX3")
lbl.grid(column=0, row=0)
def runScript():
filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("csv files","*.csv"),("all files","*.*")))
subprocess.call(['Rscript', 'C:/Users/Name/Desktop/R-GUI/test.r', filename])
btn = Button(window, text="Select a file and start Cloud creation", command=runScript())
btn.grid(column=0, row=1)
window.mainloop()


But unfortunately this is not working. I get this error but do not know what is wrong.



 File "c:Usersname.vscodeextensionsms-python.python-2019.2.5558pythonFileslibpythonptvsd_vendoredpydevd_pydev_bundlepydev_monkey.py", line 444, in new_CreateProcess
return getattr(_subprocess, original_name)(app_name, patch_arg_str_win(cmd_line), *args)
FileNotFoundError: [WinError 2] The system cannot find the file specified


I do not see why the file cannot be found.










share|improve this question



















  • 1





    Is your path correct? The FileNotFoundError informs me that you might have given it a relative path but that is not the path in which the file resides

    – Mike Tung
    Mar 27 at 13:18











  • Possible duplicate of Using a Windows path within Python's subprocess (point to an executable) [beginner]

    – Bram Vanroy
    Mar 27 at 13:26











  • I added filename = '"' + filename + '"' and filename.replace("\", "/") but still get the same error. print(filename) gives me "C:/Users/name/Desktop/file.csv"

    – ruedi
    Mar 27 at 13:45












  • Is Python script running in same environment as R? Also, use os.path.join() from built-in os module for os-agonstic file paths. Check if Python can see path with os.path.exists(). Finally, do note, R has its own GUI modules: gWidgets2, RGtk2, rattle!

    – Parfait
    Mar 27 at 13:50












  • The environment variable was not set correct. FileNotFoundError is a bit confusing here. Thanks for your help!

    – ruedi
    Mar 27 at 16:39

















0















I have a r Script with the code:



args = commandArgs(trailingOnly=TRUE)
myData <- read.csv(file=args[0])


I want to run this using a GUI and deliver a choosen csv file with this python code



from tkinter import filedialog
from tkinter import *
import subprocess

window = Tk()
window.geometry('500x200')
window.title("Wordcloud Creator")
lbl = Label(window, text="1. Please prepare a CSV (-Trennzeichen) file with the columns untgscod, berpos, SpezX3")
lbl.grid(column=0, row=0)
def runScript():
filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("csv files","*.csv"),("all files","*.*")))
subprocess.call(['Rscript', 'C:/Users/Name/Desktop/R-GUI/test.r', filename])
btn = Button(window, text="Select a file and start Cloud creation", command=runScript())
btn.grid(column=0, row=1)
window.mainloop()


But unfortunately this is not working. I get this error but do not know what is wrong.



 File "c:Usersname.vscodeextensionsms-python.python-2019.2.5558pythonFileslibpythonptvsd_vendoredpydevd_pydev_bundlepydev_monkey.py", line 444, in new_CreateProcess
return getattr(_subprocess, original_name)(app_name, patch_arg_str_win(cmd_line), *args)
FileNotFoundError: [WinError 2] The system cannot find the file specified


I do not see why the file cannot be found.










share|improve this question



















  • 1





    Is your path correct? The FileNotFoundError informs me that you might have given it a relative path but that is not the path in which the file resides

    – Mike Tung
    Mar 27 at 13:18











  • Possible duplicate of Using a Windows path within Python's subprocess (point to an executable) [beginner]

    – Bram Vanroy
    Mar 27 at 13:26











  • I added filename = '"' + filename + '"' and filename.replace("\", "/") but still get the same error. print(filename) gives me "C:/Users/name/Desktop/file.csv"

    – ruedi
    Mar 27 at 13:45












  • Is Python script running in same environment as R? Also, use os.path.join() from built-in os module for os-agonstic file paths. Check if Python can see path with os.path.exists(). Finally, do note, R has its own GUI modules: gWidgets2, RGtk2, rattle!

    – Parfait
    Mar 27 at 13:50












  • The environment variable was not set correct. FileNotFoundError is a bit confusing here. Thanks for your help!

    – ruedi
    Mar 27 at 16:39













0












0








0








I have a r Script with the code:



args = commandArgs(trailingOnly=TRUE)
myData <- read.csv(file=args[0])


I want to run this using a GUI and deliver a choosen csv file with this python code



from tkinter import filedialog
from tkinter import *
import subprocess

window = Tk()
window.geometry('500x200')
window.title("Wordcloud Creator")
lbl = Label(window, text="1. Please prepare a CSV (-Trennzeichen) file with the columns untgscod, berpos, SpezX3")
lbl.grid(column=0, row=0)
def runScript():
filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("csv files","*.csv"),("all files","*.*")))
subprocess.call(['Rscript', 'C:/Users/Name/Desktop/R-GUI/test.r', filename])
btn = Button(window, text="Select a file and start Cloud creation", command=runScript())
btn.grid(column=0, row=1)
window.mainloop()


But unfortunately this is not working. I get this error but do not know what is wrong.



 File "c:Usersname.vscodeextensionsms-python.python-2019.2.5558pythonFileslibpythonptvsd_vendoredpydevd_pydev_bundlepydev_monkey.py", line 444, in new_CreateProcess
return getattr(_subprocess, original_name)(app_name, patch_arg_str_win(cmd_line), *args)
FileNotFoundError: [WinError 2] The system cannot find the file specified


I do not see why the file cannot be found.










share|improve this question














I have a r Script with the code:



args = commandArgs(trailingOnly=TRUE)
myData <- read.csv(file=args[0])


I want to run this using a GUI and deliver a choosen csv file with this python code



from tkinter import filedialog
from tkinter import *
import subprocess

window = Tk()
window.geometry('500x200')
window.title("Wordcloud Creator")
lbl = Label(window, text="1. Please prepare a CSV (-Trennzeichen) file with the columns untgscod, berpos, SpezX3")
lbl.grid(column=0, row=0)
def runScript():
filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("csv files","*.csv"),("all files","*.*")))
subprocess.call(['Rscript', 'C:/Users/Name/Desktop/R-GUI/test.r', filename])
btn = Button(window, text="Select a file and start Cloud creation", command=runScript())
btn.grid(column=0, row=1)
window.mainloop()


But unfortunately this is not working. I get this error but do not know what is wrong.



 File "c:Usersname.vscodeextensionsms-python.python-2019.2.5558pythonFileslibpythonptvsd_vendoredpydevd_pydev_bundlepydev_monkey.py", line 444, in new_CreateProcess
return getattr(_subprocess, original_name)(app_name, patch_arg_str_win(cmd_line), *args)
FileNotFoundError: [WinError 2] The system cannot find the file specified


I do not see why the file cannot be found.







python r






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 13:16









ruediruedi

2,0416 gold badges32 silver badges61 bronze badges




2,0416 gold badges32 silver badges61 bronze badges










  • 1





    Is your path correct? The FileNotFoundError informs me that you might have given it a relative path but that is not the path in which the file resides

    – Mike Tung
    Mar 27 at 13:18











  • Possible duplicate of Using a Windows path within Python's subprocess (point to an executable) [beginner]

    – Bram Vanroy
    Mar 27 at 13:26











  • I added filename = '"' + filename + '"' and filename.replace("\", "/") but still get the same error. print(filename) gives me "C:/Users/name/Desktop/file.csv"

    – ruedi
    Mar 27 at 13:45












  • Is Python script running in same environment as R? Also, use os.path.join() from built-in os module for os-agonstic file paths. Check if Python can see path with os.path.exists(). Finally, do note, R has its own GUI modules: gWidgets2, RGtk2, rattle!

    – Parfait
    Mar 27 at 13:50












  • The environment variable was not set correct. FileNotFoundError is a bit confusing here. Thanks for your help!

    – ruedi
    Mar 27 at 16:39












  • 1





    Is your path correct? The FileNotFoundError informs me that you might have given it a relative path but that is not the path in which the file resides

    – Mike Tung
    Mar 27 at 13:18











  • Possible duplicate of Using a Windows path within Python's subprocess (point to an executable) [beginner]

    – Bram Vanroy
    Mar 27 at 13:26











  • I added filename = '"' + filename + '"' and filename.replace("\", "/") but still get the same error. print(filename) gives me "C:/Users/name/Desktop/file.csv"

    – ruedi
    Mar 27 at 13:45












  • Is Python script running in same environment as R? Also, use os.path.join() from built-in os module for os-agonstic file paths. Check if Python can see path with os.path.exists(). Finally, do note, R has its own GUI modules: gWidgets2, RGtk2, rattle!

    – Parfait
    Mar 27 at 13:50












  • The environment variable was not set correct. FileNotFoundError is a bit confusing here. Thanks for your help!

    – ruedi
    Mar 27 at 16:39







1




1





Is your path correct? The FileNotFoundError informs me that you might have given it a relative path but that is not the path in which the file resides

– Mike Tung
Mar 27 at 13:18





Is your path correct? The FileNotFoundError informs me that you might have given it a relative path but that is not the path in which the file resides

– Mike Tung
Mar 27 at 13:18













Possible duplicate of Using a Windows path within Python's subprocess (point to an executable) [beginner]

– Bram Vanroy
Mar 27 at 13:26





Possible duplicate of Using a Windows path within Python's subprocess (point to an executable) [beginner]

– Bram Vanroy
Mar 27 at 13:26













I added filename = '"' + filename + '"' and filename.replace("\", "/") but still get the same error. print(filename) gives me "C:/Users/name/Desktop/file.csv"

– ruedi
Mar 27 at 13:45






I added filename = '"' + filename + '"' and filename.replace("\", "/") but still get the same error. print(filename) gives me "C:/Users/name/Desktop/file.csv"

– ruedi
Mar 27 at 13:45














Is Python script running in same environment as R? Also, use os.path.join() from built-in os module for os-agonstic file paths. Check if Python can see path with os.path.exists(). Finally, do note, R has its own GUI modules: gWidgets2, RGtk2, rattle!

– Parfait
Mar 27 at 13:50






Is Python script running in same environment as R? Also, use os.path.join() from built-in os module for os-agonstic file paths. Check if Python can see path with os.path.exists(). Finally, do note, R has its own GUI modules: gWidgets2, RGtk2, rattle!

– Parfait
Mar 27 at 13:50














The environment variable was not set correct. FileNotFoundError is a bit confusing here. Thanks for your help!

– ruedi
Mar 27 at 16:39





The environment variable was not set correct. FileNotFoundError is a bit confusing here. Thanks for your help!

– ruedi
Mar 27 at 16:39












2 Answers
2






active

oldest

votes


















0














As suggested in comments, check that



  • your paths are correct and do not contain empty spaces or weird characters

  • files do exist in correct location

...and if it doesn´t help, you could try to use subprocess.run instead of subprocess.call.






share|improve this answer


































    0














    I don't know anything about python, so I can't help you there, but your Rscript is calling the zeroth element of your arguments, which is just an empty character.



    R starts indexing at 1.



    so if my script was:



    args <- commandArgs(trailingOnly = TRUE)
    print(args[0])


    it would return:



    [1] character(0) # this is R telling you that the atomic is a character, but it has zero length


    Your RScript should be:



    args <- commandArgs(trailingOnly = TRUE)
    MyData <- read.csv(file = args[1])


    Also, if that's your whole Rscript, 'MyData' is going to disappear as soon as that RScript closes. If you want to create a file in R, you'll need to use:



    write.table(<whatever>)


    with the appropriate arguments for your data.






    share|improve this answer

























    • Thany you. I would have been run into this without your help.

      – ruedi
      Mar 27 at 16:38













    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378150%2fcall-r-script-from-python-with-arguments%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    As suggested in comments, check that



    • your paths are correct and do not contain empty spaces or weird characters

    • files do exist in correct location

    ...and if it doesn´t help, you could try to use subprocess.run instead of subprocess.call.






    share|improve this answer































      0














      As suggested in comments, check that



      • your paths are correct and do not contain empty spaces or weird characters

      • files do exist in correct location

      ...and if it doesn´t help, you could try to use subprocess.run instead of subprocess.call.






      share|improve this answer





























        0












        0








        0







        As suggested in comments, check that



        • your paths are correct and do not contain empty spaces or weird characters

        • files do exist in correct location

        ...and if it doesn´t help, you could try to use subprocess.run instead of subprocess.call.






        share|improve this answer















        As suggested in comments, check that



        • your paths are correct and do not contain empty spaces or weird characters

        • files do exist in correct location

        ...and if it doesn´t help, you could try to use subprocess.run instead of subprocess.call.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 27 at 14:03

























        answered Mar 27 at 13:56









        OkaOka

        8082 silver badges9 bronze badges




        8082 silver badges9 bronze badges


























            0














            I don't know anything about python, so I can't help you there, but your Rscript is calling the zeroth element of your arguments, which is just an empty character.



            R starts indexing at 1.



            so if my script was:



            args <- commandArgs(trailingOnly = TRUE)
            print(args[0])


            it would return:



            [1] character(0) # this is R telling you that the atomic is a character, but it has zero length


            Your RScript should be:



            args <- commandArgs(trailingOnly = TRUE)
            MyData <- read.csv(file = args[1])


            Also, if that's your whole Rscript, 'MyData' is going to disappear as soon as that RScript closes. If you want to create a file in R, you'll need to use:



            write.table(<whatever>)


            with the appropriate arguments for your data.






            share|improve this answer

























            • Thany you. I would have been run into this without your help.

              – ruedi
              Mar 27 at 16:38















            0














            I don't know anything about python, so I can't help you there, but your Rscript is calling the zeroth element of your arguments, which is just an empty character.



            R starts indexing at 1.



            so if my script was:



            args <- commandArgs(trailingOnly = TRUE)
            print(args[0])


            it would return:



            [1] character(0) # this is R telling you that the atomic is a character, but it has zero length


            Your RScript should be:



            args <- commandArgs(trailingOnly = TRUE)
            MyData <- read.csv(file = args[1])


            Also, if that's your whole Rscript, 'MyData' is going to disappear as soon as that RScript closes. If you want to create a file in R, you'll need to use:



            write.table(<whatever>)


            with the appropriate arguments for your data.






            share|improve this answer

























            • Thany you. I would have been run into this without your help.

              – ruedi
              Mar 27 at 16:38













            0












            0








            0







            I don't know anything about python, so I can't help you there, but your Rscript is calling the zeroth element of your arguments, which is just an empty character.



            R starts indexing at 1.



            so if my script was:



            args <- commandArgs(trailingOnly = TRUE)
            print(args[0])


            it would return:



            [1] character(0) # this is R telling you that the atomic is a character, but it has zero length


            Your RScript should be:



            args <- commandArgs(trailingOnly = TRUE)
            MyData <- read.csv(file = args[1])


            Also, if that's your whole Rscript, 'MyData' is going to disappear as soon as that RScript closes. If you want to create a file in R, you'll need to use:



            write.table(<whatever>)


            with the appropriate arguments for your data.






            share|improve this answer













            I don't know anything about python, so I can't help you there, but your Rscript is calling the zeroth element of your arguments, which is just an empty character.



            R starts indexing at 1.



            so if my script was:



            args <- commandArgs(trailingOnly = TRUE)
            print(args[0])


            it would return:



            [1] character(0) # this is R telling you that the atomic is a character, but it has zero length


            Your RScript should be:



            args <- commandArgs(trailingOnly = TRUE)
            MyData <- read.csv(file = args[1])


            Also, if that's your whole Rscript, 'MyData' is going to disappear as soon as that RScript closes. If you want to create a file in R, you'll need to use:



            write.table(<whatever>)


            with the appropriate arguments for your data.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 27 at 15:26









            NickNick

            115 bronze badges




            115 bronze badges















            • Thany you. I would have been run into this without your help.

              – ruedi
              Mar 27 at 16:38

















            • Thany you. I would have been run into this without your help.

              – ruedi
              Mar 27 at 16:38
















            Thany you. I would have been run into this without your help.

            – ruedi
            Mar 27 at 16:38





            Thany you. I would have been run into this without your help.

            – ruedi
            Mar 27 at 16:38

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378150%2fcall-r-script-from-python-with-arguments%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현