在 R 中,我编写了一个如下函数:
\n\nfun <- function(A, B, C, D) {}\nRun Code Online (Sandbox Code Playgroud)\n\n因此,在这个函数的开头,我必须进行参数检查:
\n\n但是关于这些参数,有些是必需的,有些不是,并且每个参数的类(数据类型)必须是我想要的,例如:numeric,Logical等等......
\n\n为了实现这一点,我做了类似 \xef\xbc\x9a 的事情
\n\nif(A Follow_the_rule){}\nif(B Follow_the_rule){}\nif(C Follow_the_rule){}\n...\nRun Code Online (Sandbox Code Playgroud)\n\n关于上面的代码,就这么多if语句,我认为这不是参数检查的最佳方法。
\n\n所以有没有更好的方法来检查 R 中的参数呢?
\n\n任何帮助将不胜感激。
\n我必须检测文件是否是有效的 mp3 文件。到目前为止,我找到了两个解决方案,包括:
来自 Peter Carroll 的这个解决方案
使用try-catch表达式:
try:
_ = librosa.get_duration(filename=mp3_file_path)
return True
except:
return False
Run Code Online (Sandbox Code Playgroud)
上述两种解决方案都有效,但可能有一些缺点,第一个解决方案似乎太复杂而第二个解决方案太慢(以秒为单位,取决于音频的长度)。所以我想知道是否有更好的方法用python验证mp3文件?
谢谢。
int*到char*:
int* pNum = new int[1];
pNum[0] = 57;
char* pChar = reinterpret_cast< char* >(pNum);
float* pFloat = new float[1]; pFloat[0] = 57; //assign the same value as before char* pChar = reinterpret_cast< char* >(pFloat);
结果:pChar [0] ='a';
那么为什么我得到两个不同的结果呢?
谢谢你的帮助.