Skip to content

Commit 9b499a6

Browse files
authored
Merge pull request #163 from NathanSkene/patch-1
Added basic error catches to the R interface
2 parents 5218852 + 3f16ebf commit 9b499a6

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

R/svm.R

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
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+
2323
svm_train_R <-
2424
function(
2525
svm_type = 0, kernel = 2,degree = 3,gamma = 'auto',
@@ -28,6 +28,8 @@ tol = 0.001, probability = FALSE, class_weight = 'None', cv = '-1',
2828
verbose = 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(
4042
test_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

Comments
 (0)