I am trying to create a csv file and zip it from a script. The first part works fine and abc.csv is created (assuming abc is the filename). I am able to see the file by navigating to the path.
After creating the file, I am trying to zip it using the below command
zip abc.zip abc.csv
I am getting the following error
zip warning: name not matched: abc.csv
zip error: Nothing to do! (abc.zip)
If I navigate to the path, I am able to execute zip abc.zip abc.csv without any issues.
Can you please suggest where I am going wrong.
Related
I have a python code that is taking some info from a website by selenium and then write them into a json file, after I created an '.exe' file by pyinstaller and run it I don't know where this json file is saved.
Where could be saved, should be in the initial directory?
I am creating an R script myscript.R which manipulates an excel file by means of XLConnectpackage.
The point is it refers to several external files: the excel file itself and another R file (functions library), so I need to set a working directory in the location of the script (so that relative paths to external files work properly).
I am using the following in my script
new_wd <- dirname(sys.frame(1)$ofile)
setwd(new_wd)
When I source the script from my RStudio it gets the job done. The problem is that the script is to be used by non-programmers, non-Rstutio-users, so I create .bat file (which I want to turn into an .exe one)
"C:\Program Files\R\R-4.0.3\bin\Rscript.exe" "C:\my\path\to\myscript.R"
It executes the script line by line but sys.frame(1) only works when sourcing.
How could I solve it?
Thanx
I have found a solution and it works properly.
From CMD command line or from a .bat file one can add an argument -e to the command, so that you can use a R language.
absolute\path\to\Rscript.exe -e "source('"relative\path\to\myscript.R"')"
It worked for me.
Besides, as Compo commented, I think there's no need for a .exe file, since a .bat does the job.
I have successfully run a simple cronR tutorial using the cronR add in within R Studio. Here is the following code that I have saved in a R script file:
library(glue)
current_time <- Sys.time()
print(current_time)
msg <- glue::glue("This is a test I am running at {current_time}.")
cat(msg, file = "test.txt")
The R script file is saved within a specific project directory. The log file when the job runs is also saved there. However, the output of the script file, test.txt, is saved in my home directory. I am on a Mac. In the tutorial, it was stated that this would happen, that cron would save any output in the home directory and that if I want to change the location that I have to "specify otherwise". However, the tutorial gives no instructions for how to do this and I am not sure if I am supposed to do this through the terminal in mac and if so how? Changing the file path in the script file (e.g. Documents/test.txt) changes nothing, as the test.txt file is still saved in the home drive. I suspect I have to make this change somewhere else but I am not sure where. Any help would be appreciated.
For anyone who runs into the same issue, I was able to solve my problem by using launchD. I followed this tutorial https://babichmorrowc.github.io/post/launchd-jobs/. It worked as anticipated and now my .txt file is saved to the correct place. There is also a tutorial there for cron jobs, though if you are on a mac, launchD is apparently the preferred method.
I'm trying to create a script in R that will:
Check if a folder exists and if not, create it
Download a csv file from the internet and place it in the specified folder
The script executes Part 1 fine and creates the folder, however it won't execute Part 2 and download the file automatically. I have to do this manually in RStudio and it works, but I want it to run automatically
Created a script with just Part 2 and it executes fine.
#Create directory first
if (!file.exists("data")) {
dir.create("data")
}
#Download file
fileUrl <-"https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv"
download.file(fileUrl, destfile = "./data/cameras.csv")
}
There are no error messages, it just executes Part 1 but does not execute Part 2.
Can someone advise what I'm missing here? TIA
Thanks it is working now. It worked in R console but not Studio but worked after restarting R Studio. Thanks all for the input
How to get the robot generated log file name and log directory.
I want to write a post process script, which can process the output XML file generated by robot.
${LOG FILE}
Gives you absolute path to the log file.
${SUITE SOURCE}
Gives you absolute path to the suite file.
${OUTPUT DIR}
Gives you absolute path to the output directory.
http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.8.4#automatic-variables
The easiest thing is to tell robot where you want the file to be, then you don't have to figure it out. Use the output directory command line option --outputdir. Unless you tell it where to put the output files, they will go into the current working directory.
If neither one of those works, you can capture the output of robot, and the last three lines will tell you the location of the output.xml, log.html and report.html files.