我是linux和shell脚本编程的新手.我试图使用以下命令从Linux上的安全shell(ssh)运行一个shellcript:
chmod +x path/to/mynewshell.sh
sh path/to/mynewshell.sh
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
path/to/mynewshell.sh: path/to/mynewshell.sh: cannot execute binary file.
Run Code Online (Sandbox Code Playgroud)
尝试使用此命令:
bash path/to/mynewshell.sh
Run Code Online (Sandbox Code Playgroud)
我犯了同样的错误.
试过这个命令:su - myusername sh path/to/mynewshell.sh
它要求我的密码并给我这个错误:no such file or directory
.
1. cat -v path/to/mynewshell.sh的结果是:^ @ ^ @ ^ @ ^ @ ^ @ ^ @ ^ @ ^ @ Rscript"$ dir"/diver_script.R done
2.当我尝试'less path/to/mynewshell.sh'时,我在终端上得到了这个:
#!/bin/bash/Rscript^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
for dir in /path/to/* ; do
^@^@^@^@^@^@^@^@Rscript "$dir"/myRscript.R
done
Run Code Online (Sandbox Code Playgroud)
3.当我运行文件路径/到/ mynewshell.sh时:我得到了这个"Bourne-Again shell脚本文本可执行文件"
请提供有关如何尝试执行shellscript的任何建议.
我正在运行一个R脚本,该脚本每隔一小时读取一次Google表格。我为此使用googlesheets软件包和gs_auth()函数。最初,我通过交互式身份验证运行gs_auth()来存储令牌。从下一次开始,代码将仅读取保存的令牌并运行gs_auth(token = ...)函数进行身份验证。这是示例代码。
## One time execution to save token ##
token <- gs_auth(cache = TRUE)
saveRDS(token, file = "/myfilepath/googlesheets_token.rds")
## reading the saved token everytime the R script runs ##
gs_auth(token = "/myfilepath/googlesheets_token.rds")
Run Code Online (Sandbox Code Playgroud)
这可以正常工作几个小时,然后给我这个错误。
Auto-refreshing stale OAuth token.
Error in function_list[[k]](value) : Unauthorized (HTTP 401).
In addition: Warning message:
Unable to refresh token
Run Code Online (Sandbox Code Playgroud)
每次发生这种情况时,我都会运行两行一次的代码并存储一个新令牌,这又会运行几个小时,然后出现相同的错误。我也使用cache = FALSE
代替TRUE
,尽管我不清楚要使用哪个及其用途。但这并没有解决。我也尝试在每次使用in之前从本地目录读取令牌时刷新令牌gs_auth()
。
t <- readRDS(file = "/myfilepath/googlesheets_token.rds")
t$refresh()
gs_auth(token = t)
Run Code Online (Sandbox Code Playgroud)
有没有什么方法可以解决此问题,并使每次身份验证都能正常工作而无需交互版本。
我正在尝试使用eval()
R中的函数来计算表达式。我正在从数据框中检索公式,并将其存储在变量中,例如“ form”。现在,我尝试按以下方式评估此表达式:
df
x y z
1 2 3
4 5 6
7 8 9
form = "x+y+z"
expr = expression(form)
df = data.table::data.table(df)
result = eval(expr, df[1])
Run Code Online (Sandbox Code Playgroud)
我得到的结果是“ x + y + z”而不是6。如果将公式直接传递给expr = expression(..)
,则得到正确的结果,但是我无法做到这一点,所以我正在从其他数据框中检索公式。请提出建议。
我有这样的表达方式abs(iodlin_vod2*1e6)/(array*nfin*nrx*nfinger*weff)
.我的代码使用分割此表达式strsplit
.现在,根据这个结果,我应该检查每个单词是否是数学函数,如果不是,我应该执行一些操作.如果它是数学函数,我会坚持检查这个词.有人可以请帮助.
Qsn编辑:这是结果 strsplit
sstemp
[1] "abs" "iodlin_vod2 " " 1e+06" "array " " nfin "
" nrx "
[7] " nfinger " " weff"
Run Code Online (Sandbox Code Playgroud)
我想消除abs
并1e+06
从进一步的操作在我的代码.