1- if (Sys.info()[' sysname' ] == ' Windows' ){
2- if (! file.exists(" ../build/bin/Debug/thundersvm.dll" )){
3- print(" Please build the library first!" )
4- quit()
5- }
6- dyn.load(" ../build/bin/Debug/thundersvm.dll" )
7- } else if (Sys.info()[' sysname' ] == ' Linux' ){
8- if (! file.exists(" ../build/lib/libthundersvm.so" )){
9- print(" Please build the library first!" )
10- quit()
11- }
12- dyn.load(" ../build/lib/libthundersvm.so" )
13- } else if (Sys.info()[' sysname' ] == ' Darwin' ){
14- if (! file.exists(" ../build/lib/libthundersvm.dylib" )){
15- print(" Please build the library first!" )
16- quit()
17- }
18- dyn.load(" ../build/lib/libthundersvm.dylib" )
19- } else {
20- print(" OS not supported!" )
21- quit()
1+ check_location <- function (){
2+ if (Sys.info()[' sysname' ] == ' Windows' ){
3+ if (! file.exists(" ../build/bin/Debug/thundersvm.dll" )){
4+ stop(" Please build the library first (or check you called this while your workspace is set to the thundersvm/R/ directory)!" )
5+ }
6+ dyn.load(" ../build/bin/Debug/thundersvm.dll" )
7+ } else if (Sys.info()[' sysname' ] == ' Linux' ){
8+ if (! file.exists(" ../build/lib/libthundersvm.so" )){
9+ stop(" Please build the library first (or check you called this while your workspace is set to the thundersvm/R/ directory)!" )
10+ }
11+ dyn.load(" ../build/lib/libthundersvm.so" )
12+ } else if (Sys.info()[' sysname' ] == ' Darwin' ){
13+ if (! file.exists(" ../build/lib/libthundersvm.dylib" )){
14+ stop(" Please build the library first (or check you called this while your workspace is set to the thundersvm/R/ directory)!" )
15+ }
16+ dyn.load(" ../build/lib/libthundersvm.dylib" )
17+ } else {
18+ stop(" OS not supported!" )
19+ }
2220}
21+ check_location() # Run this when the file is sourced
22+
2323svm_train_R <-
2424function (
2525svm_type = 0 , kernel = 2 ,degree = 3 ,gamma = ' auto' ,
@@ -28,6 +28,8 @@ tol = 0.001, probability = FALSE, class_weight = 'None', cv = '-1',
2828verbose = FALSE , max_iter = - 1 , n_cores = - 1 , dataset = ' None' , model_file = ' None'
2929)
3030{
31+ check_location()
32+ if (! file.exists(dataset )){stop(" The file containing the training dataset provided as an argument in 'dataset' does not exist" )}
3133 res <- .C(" train_R" , as.character(dataset ), as.integer(kernel ), as.integer(svm_type ),
3234 as.integer(degree ), as.character(gamma ), as.double(coef0 ), as.double(nu ),
3335 as.double(cost ), as.double(epsilon ), as.double(tol ), as.integer(probability ),
@@ -40,5 +42,8 @@ function(
4042test_dataset = ' None' , model_file = ' None' , out_file = ' None'
4143)
4244{
45+ check_location()
46+ if (! file.exists(test_dataset )){stop(" The file containing the training dataset provided as an argument in 'test_dataset' does not exist" )}
47+ if (! file.exists(model_file )){stop(" The file containing the model provided as an argument in 'model_file' does not exist" )}
4348 res <- .C(" predict_R" , as.character(test_dataset ), as.character(model_file ), as.character(out_file ))
44- }
49+ }
0 commit comments