Closed earthcli closed 6 years ago
I have tried that: options(encoding="UTF-8") taskscheduler_ls()
but it does not works.
Hmm, I don't know what your problem is. Can you show me the file which is generated with
cmd <- sprintf('schtasks /Query /FO CSV /V')
x <- system(cmd, intern = TRUE)
f <- tempfile()
writeLines(x, f)
Did you try to run the following code taskscheduler_ls(encoding = 'UTF-8')
or whichever encoding you have.
Thanks for your response. after run the script, the generated file content is : 错误: 无法加载列资源。
this is because the default encoding of my computer( in chinese), I can sucessfully run it after chcp 437
this works:
cmd="chcp 437" x <- system(cmd, intern = TRUE) taskscheduler_ls()
HostName TaskName Next Run Time Status Logon Mode 1 360ZipUpdater N/A Ready Interactive only 2 At1 N/A Ready Interactive/Background 3 At10 N/A Ready Interactive/Background 4 At11 N/A Ready Interactive/Background
I have another question, how can I achieve system sleep at specific time with taskscheduler_create function? Is taskscheduler_create allow a windows cmd bat file as input ?
Thanks for the suggest on chcp. Can you tell me what the following gives on your machine?
system("chcp 65001", intern = TRUE)
taskscheduler_ls(encoding = "UTF-8")
The package currently does not handle bat files. About system sleep, it's unclear what you mean. Do you mean taskscheduler_stop
? All commands which can be passed on to taskscheduler_create
are listed in the help. Extra arguments which are not listed in the help of that function are available in the schtasks.exe manual: https://github.com/bnosac/taskscheduleR/blob/master/inst/docs/schtasks.pdf and can be passed as in the schtasks_extra
argument of taskscheduler_create
Thanks for your kindly response. The "chcp 65001" command works fine on my computer. HostName TaskName Next Run Time Status Logon Mode 1 360ZipUpdater N/A Ready Interactive only 2 At1 N/A Ready Interactive/Background
the requirement of system sleep task is meaning for the computer sleep (weak up), Because there is no function for computer sleep in R, I have to write a cmd bat scrip as follow (writted in systemsleep.bat): rundll32.exe powrprof.dll,SetSuspendState
Now I can write a R scrip with one line: system(command="systemsleep.bat"), and then use taskscheduler_create to force my computer sleep at specific time, but there should be a directly way. I have learned from the source code of taskscheduler_create function, this may be achieved if you add a cmdbatfilename name as input and replace the task string if the cmdbatfilename parameter not missing. Or you can add another function for scheduler based on general windows bat file.
Thank you very much for your work.
I made a fix by changing the codepage to 65001 (UTF-8). Current taskscheduler_create does not handle .bat files. Feel free to make a pull request with the changes needed to support these.
Closing this as fix was done changing the codepage to UTF-8. If you want to let the taskscheduler_create to handle bat files, please create a new issue.
I'm having the same issues but I don't know how to change the encoding. I'm using the addin in RStudio. How can I change the encoding to UTF-8 (which I think will solve my problem)?
which version of taskscheduleR are you using?
I have the latest version, 1.4
What does the following give you
installed.packages()["taskscheduleR", ]
taskscheduler_ls()
system("chcp 65001", intern = TRUE)
cmd <- sprintf('schtasks /Query /FO CSV /V')
system(cmd, intern = TRUE)
I'm not 100% sure what you want me to paste but I assume you want this?
"\"COMPUTERNAME\",\"\elko1.R\",\"6.2.2019 18:30:00\",\"Ready\",\"Interactive only\",\"30.11.1999 00:00:00\",\"267011\",\"COMPANY\user\",\"cmd /c C:/PROGRA~1/R/R-35~1.2/bin/Rscript.exe \"H:/Rwd/gagnasofnun/elko/elko1.R\" >> \"H:/Rwd/gagnasofnun/elko/elko1.log\" 2>&1\",\"N/A\",\"N/A\",\"Enabled\",\"Disabled\",\"Stop On Battery Mode, No Start On Batteries\",\"user\",\"Disabled\",\"72:00:00\",\"Scheduling data is not available in this format.\",\"Daily \",\"18:30:00\",\"6.2.2019\",\"N/A\",\"Every 1 day(s)\",\"N/A\",\"Disabled\",\"Disabled\",\"Disabled\",\"Disabled\""
taskscheduler_ls() gives this warning message
Warning message: In data.table::fread(f, encoding = encoding, ...) : Found and resolved improper quoting in first 100 rows. If the fields are not quoted (e.g. field separator does not appear within any field), try quote="" to avoid this warning.
The full output of the code and what it shows is needed to see what your problem is.
I solved the problem. Instead of scheduling myscript.R I now schedule myscript_2.R where myscript_2.R has only one line of code: source(myscript.R, encoding = "UTF-8").
That doesn't look like you had an encoding problem as mentioned in this thread but only R code with a different encoding than e.g. ASCII
Thanks Vidaringa, Thanks to your hint, I did the same workaround to schedule a script with UTF-8 encoding. I have set the global option in RStudio for this encoding, but it did not work. Maybe there are other options to set in profile, which I didn't find out. It would be good if there would be an option in taskscheduler_create() to set encoding. Anyways, thank you for taskscheduleR! Great work!
The taskscheduleR is a wonderful package that my help me a lot. but I have a problem with using it in my windows7 system, with the default encoding of CP936, generally, there is an error when run taskscheduler_ls in R, and also in the cmd window when running schtasks.exe /query , 错误: 无法加载列资源。 when debug from the cmd: chcp 936 after run chcp 437, I can run schtasks.exe /query successfully,
so I must open a cmd window, do "chcp 437", and then open R.exe in the same cmd window, and then using the function in taskscheduleR, such as taskscheduler_ls, I wonder how I can do this in RStudio, that is change encoding in R, and then using taskscheduler_ls functions?
Matrix products: default
locale: [1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936 [2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936 [4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936