Using Discretization from Training Set on Test Set in R
You need to save the breaks/endpoints when you perform the bucketing/discretization on the training set as a (named) vector. The same breaks/endpoints can be then re-used on test set.

The I am giving below sample code using cut function in base R to keep the answer more generally applicable (rather than giving answer specific to bnlearn package). Note the way output of quantile function is saved in vector breaks_to_use in line 3 below and re-used while applying cut on test data. You can (hopefully) do the same using the breaks argument in discretize function.

training_data &lt;- runif(100)
test_data &lt;- runif(100)
breaks_to_use &lt;- quantile(training_data, seq(0, 1, 0.25))
discretized_training_data &lt;- cut(training_data, breaks = breaks_to_use)
discretized_test_data &lt;- cut(test_data, breaks = breaks_to_use)