Title: | Virtual Machines for R |
---|---|
Description: | Manage, provision and use Virtual Machines pre-configured for R. Develop, test and build package in a clean environment. 'Vagrant' tool and a provider (such as 'Virtualbox') have to be installed. |
Authors: | Jean-François Rey [cre, aut] |
Maintainer: | Jean-François Rey <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.0.6 |
Built: | 2024-12-01 08:11:05 UTC |
Source: | CRAN |
Manage, provision and use Virtual Machines pre-configured for R. Develop, test and build package in a clean environment. 'Vagrant' tool and a provider (such as 'Virtualbox') have to be installed.
Package: | vmr |
Type: | Package |
Version: | 0.0.6 |
Date: | 2023-03-07 |
License: | GPL (>=3) |
This package is a wrap of the Vagrant
tool and more.
It allows to manage, provision and use Virtual Machines pre-configured for R.
It currently only uses 'Virtualbox' (>= 6.1.14) as provider.
Vagrant tool have to be installed too.
Used VMs come from https://app.vagrantup.com/VMR
repository and the sources use to generate them can be found at
https://gitlab.com/rstuff/vms.
See vignettes for the documentations browseVignette("vmr")
.
Jean-François Rey [email protected]
Maintainer: Jean-François Rey [email protected]
Useful links:
Report bugs at https://gitlab.com/rstuff/vmr/-/issues
## Not run: library("vmr") ## End(Not run)
## Not run: library("vmr") ## End(Not run)
List a provider available options.
getProviderOptions(provider = "virtualbox", details = FALSE)
getProviderOptions(provider = "virtualbox", details = FALSE)
provider |
a provider name |
details |
if TRUE print options, otherwise return default options |
It return a list of options name and value for a specific provider.
To get the help page do ?<provider_name>Options()
, for example [virtualboxOptions()
].
a list of options
vbOpts <- getProviderOptions(provider = "virtualbox") print(vbOpts)
vbOpts <- getProviderOptions(provider = "virtualbox") print(vbOpts)
print information from a vmr object
## S3 method for class 'vmr' print(x, ...)
## S3 method for class 'vmr' print(x, ...)
x |
a vmr object |
... |
optional print arguments |
the vmr object (via invisible(x))
print information from a vmr object
## S3 method for class 'vmr' summary(object, ...)
## S3 method for class 'vmr' summary(object, ...)
object |
a vmr object |
... |
optional print arguments |
the vmr object (via invisible(x))
Configure the guest VM to be use as a GitLab Runner and return the command to run in shell to register it.
virtualboxGitlabRunner( vmr, gitlab_url, gt_token, snapshot_name = "", vm_name = "" )
virtualboxGitlabRunner( vmr, gitlab_url, gt_token, snapshot_name = "", vm_name = "" )
vmr |
a vmr object |
gitlab_url |
a GitLab URL with protocol (http or https) |
gt_token |
a GitLab registration token |
snapshot_name |
name of a snapshot to use if any |
vm_name |
the 'VitualBox' VM name if not specified in 'vmr' object provider_options. |
Character command to run in shell to register it
## Not run: cmd <- virtualboxGitLabRunner(vmr, "gitlab.com", "mytoken") system(cmd) ## End(Not run)
## Not run: cmd <- virtualboxGitLabRunner(vmr, "gitlab.com", "mytoken") system(cmd) ## End(Not run)
List available options for 'VirtualBox' provider
virtualboxOptions(details = TRUE)
virtualboxOptions(details = TRUE)
details |
if TRUE print options (default), otherwise only return default options |
Get the 'VirtualBox' default options. It return a list as follow:
list( gui = TRUE, name = NULL, nic_type = NULL, linked_clone = FALSE, check_guest_additions = TRUE, modifyvm = list(cpus = "2", memory = "4096") )
gui: if TRUE show the GUI, otherwise headless mode is actived
name: the 'VirtualBox' instance name
nic_type: the NIC type for the network interface to use, by default use the default one. see VirtualBox Networking
linked_clone: if TRUE, linked clones are based on a master VM, which is generated by importing the base box only once the first time it is required. For the linked clones only differencing disk images are created where the parent disk image belongs to the master VM. (Be careful, master VM can't be remove until linked_clone still exists)
check_guest_additions: If TRUE (default) check if guest have guest additions installed.
modifyvm: list of 'VirtualBox' properties for the guest VM (such as number of cpus, memory size,...). see 'VirtualBox' modifyvm
A default list of options
list( gui = TRUE, name = NULL, nic_type = NULL, linked_clone = FALSE, check_guest_additions = TRUE, modifyvm = list(cpus = "2", memory = "4096") )
## Not run: vb.opts <- virtualboxOptions(details = FALSE) vb.opts$modifyvm$cpus <- "4" vb.opts$modifyvm$memory <- "8192" vb.opts ## End(Not run)
## Not run: vb.opts <- virtualboxOptions(details = FALSE) vb.opts$modifyvm$cpus <- "4" vb.opts$modifyvm$memory <- "8192" vb.opts ## End(Not run)
Download a box from a vmr object.
vmrBoxDownload(vmr)
vmrBoxDownload(vmr)
vmr |
a vmr object |
a vmr object
Configure ssh credential.
vmrConfigSSH( vmr, ssh_user = "vagrant", ssh_pwd = "vagrant", port = "", ssh_private_key_path = "" )
vmrConfigSSH( vmr, ssh_user = "vagrant", ssh_pwd = "vagrant", port = "", ssh_private_key_path = "" )
vmr |
a vmr object |
ssh_user |
the ssh user (default 'vagrant') |
ssh_pwd |
the ssh pwd if any (default 'vagrant') |
port |
the ssh port (default empty) |
ssh_private_key_path |
path to the private ssh key to use (default empty, use insecure vagrant key) |
by default vmr use vagrant as user/password and insecure key for ssh connection. This behavior can be change here, by setting an another user and/or ssh keys. Calling with no arguments will disable this option. Be careful, ssh using only password may result of vmr functions bugs.
an updated vmr object
## Not run: vmr <- vmrConfigSSH(ssh_user = "John", ssh_pwd = "d0e", port = "22") vmr <- vmrConfigSSH(ssh_user = "John", private_key_path = "/path/to/private/key/") ## End(Not run)
## Not run: vmr <- vmrConfigSSH(ssh_user = "John", ssh_pwd = "d0e", port = "22") vmr <- vmrConfigSSH(ssh_user = "John", private_key_path = "/path/to/private/key/") ## End(Not run)
Open a ssh connection to guest machine
vmrConnect(vmr)
vmrConnect(vmr)
vmr |
a vmr object |
To open a ssh connection 'ssh' package have to be installed.
a vmr object
Create a vmr object.
vmrCreate( name, provider = "virtualbox", version = "latest", provider.options = virtualboxOptions(FALSE) )
vmrCreate( name, provider = "virtualbox", version = "latest", provider.options = virtualboxOptions(FALSE) )
name |
a box name |
provider |
the box provider (default: "virtualbox") |
version |
the box version (default : "latest") |
provider.options |
provider options (call [ |
Create a S3 vmr object (a simple list). The object contains all information needed to configure and manage a vmr environment (a vagrant environment).
A vmr environment need mostly a box name and a provider. The environment is attached to the current working directory.
vmr object main attributs:
path: working directory
org: Vagrant cloud user/organization name 'VMR'
box: the box name
version: the box version
provider: the provider
provider_options: the provider options (see [getProviderOptions()
])
vagrantName: Vagrant environment name
ID <- Vagrant environment ID
synced_folder: a list with source and destination
ssh_user: the ssh user
ssh_pwd: the ssh user password
ssh_port: the ssh port
ssh_private_key_path: the private ssh key path
a vmr object (see details)
## Not run: # List boxes available boxes <- vmrList() # Create a vmr object vmr <- vmrCreate(boxes$Name[1]) # to customize the guest machine for virtualbox virtualboxOpts <- getProviderOptions(provider = "virtualbox") virtualboxOpts$modifyvm <- list(cpus = 4, memory = 4096) virtualboxOpts$name <- "My VM Cool Name" # To specify a provider and version vmr <- vmrCreate( name = boxes$Name[1], provider = "virtualbox", version = boxes$Version[1], provider.options = virtualboxOpts ) ## End(Not run)
## Not run: # List boxes available boxes <- vmrList() # Create a vmr object vmr <- vmrCreate(boxes$Name[1]) # to customize the guest machine for virtualbox virtualboxOpts <- getProviderOptions(provider = "virtualbox") virtualboxOpts$modifyvm <- list(cpus = 4, memory = 4096) virtualboxOpts$name <- "My VM Cool Name" # To specify a provider and version vmr <- vmrCreate( name = boxes$Name[1], provider = "virtualbox", version = boxes$Version[1], provider.options = virtualboxOpts ) ## End(Not run)
Remove all resources created by vmrStart()
vmrDestroy(id = "", force = FALSE)
vmrDestroy(id = "", force = FALSE)
id |
a vmr environment id (default : "" id from the current environment) |
force |
if TRUE force to remove |
Will by default remove all resources created from the current vmr environment. By specifying the id any environment with this id will be remove.
the vagrant environment id
## Not run: vmrStop() vmrDestroy() ## End(Not run)
## Not run: vmrStop() vmrDestroy() ## End(Not run)
Close a ssh connection to the guest machine
vmrDisconnect(vmr)
vmrDisconnect(vmr)
vmr |
a vmr object |
'ssh' package need to be installed.
a vmr object
Run R method into guest machine.
vmrExec(cmd = c())
vmrExec(cmd = c())
cmd |
list of R command |
call Rscript -e "cmd" into the guest machine from the current vmr environment. Command are independents and do not keep memory of past commands.
NULL
## Not run: cmd <- c("Sys.info()", 'print("Hello World!")') vmrExec(cmd) ## End(Not run)
## Not run: cmd <- c("Sys.info()", 'print("Hello World!")') vmrExec(cmd) ## End(Not run)
Get guest machine information. Print OS, R, R-devel and R packages information. Still in development.
vmrInfo()
vmrInfo()
NULL
## Not run: boxes <- vmrList() vmr <- vmrCreate(boxes$Name[1]) vmr <- vmrInitEnv(vmr) vmrStart() vmrInfo() ## End(Not run)
## Not run: boxes <- vmrList() vmr <- vmrCreate(boxes$Name[1]) vmr <- vmrInitEnv(vmr) vmrStart() vmrInfo() ## End(Not run)
Create vmr environment in the current directory. Set configuration into a template file name "Vagrantfile" and download the box if needed.
vmrInitEnv(vmr, force.vagrantfile = FALSE, force.download = FALSE)
vmrInitEnv(vmr, force.vagrantfile = FALSE, force.download = FALSE)
vmr |
a vmr object |
force.vagrantfile |
if TRUE force to overwrite environment configuration (default FALSE) |
force.download |
if TRUE force to download the box, otherwise do not (default FALSE). |
The vmr environment consist of a directory (the working directory) and a template file name Vagrantfile. If the box is not present in localhost it will be download.
the vmr object
## Not run: boxes <- vmrList() vmr <- vmrCreate(boxes$Name[1]) vmr <- vmrInitEnv(vmr) ## End(Not run)
## Not run: boxes <- vmrList() vmr <- vmrCreate(boxes$Name[1]) vmr <- vmrInitEnv(vmr) ## End(Not run)
Install a list of R packages into the guest machine of the current vmr environment.
vmrInstallPackages(pkgs = c())
vmrInstallPackages(pkgs = c())
pkgs |
list of R packages |
installed packages vector
## Not run: vmrInstallPackages(c("vmr")) ## End(Not run)
## Not run: vmrInstallPackages(c("vmr")) ## End(Not run)
Check if a guest machine in a vmr environment is running
vmrIsRunning()
vmrIsRunning()
TRUE if running, otherwise FALSE
## Not run: lboxes <- vmrList() vmr <- vmrCreate(lboxes$Name[1]) vmr <- vmrInitEnv(vmr) vmrStart() vmrIsRunning() vmrStop() vmrIsRunning() ## End(Not run)
## Not run: lboxes <- vmrList() vmr <- vmrCreate(lboxes$Name[1]) vmr <- vmrInitEnv(vmr) vmrStart() vmrIsRunning() vmrStop() vmrIsRunning() ## End(Not run)
List of available boxes from a VagrantCloud organization account.
vmrList(org = .VagrantCloudOrganization)
vmrList(org = .VagrantCloudOrganization)
org |
Vagrant Cloud organization name (default : 'VMR') |
Default usage lists boxes preconfigurated with R from VMR organization account.
a data.frame with Name, Provider, Version and Description of available boxes
List all versions and providers available of a box.
vmrListBox(box_name, org = .VagrantCloudOrganization)
vmrListBox(box_name, org = .VagrantCloudOrganization)
box_name |
the box name |
org |
Vagrant Cloud organization name (default : 'VMR') |
List information of a box from VagrantCloud. Default usage list information of a box preconfigurated with R from VMR organization account.
a data.frame with "Name, "Version", "Description", "Provider" and "Date" of the box
## Not run: # List Boxes boxes <- vmrList() # Box informaion box_info <- vmrListBox(boxes$Name[1]) box_info ## End(Not run)
## Not run: # List Boxes boxes <- vmrList() # Box informaion box_info <- vmrListBox(boxes$Name[1]) box_info ## End(Not run)
Print all snapshot name of the guest machine
vmrListSnapshot()
vmrListSnapshot()
NULL
Load a vmr environment containing a VagrantFile
and create a vmr object (see [vmrCreate()
] for object details).
vmrLoad(dir = "./", vagrantfileName = "Vagrantfile")
vmrLoad(dir = "./", vagrantfileName = "Vagrantfile")
dir |
the vmr environment directory (default: "./") |
vagrantfileName |
a Vagrantfile name (default: "Vagrantfile") |
It read a Vagrant file template with vmr compatible parameters. It's an experimental Vagrant file reading, some parameters may not be loaded.
a vmr object
## Not run: # load the Vagrantfile in the current directory vmr <- vmrLoad(getwd()) ## End(Not run)
## Not run: # load the Vagrantfile in the current directory vmr <- vmrLoad(getwd()) ## End(Not run)
List all boxes downloaded in localhost
vmrLocalBoxList()
vmrLocalBoxList()
a data.frame with boxes Name, Providers and Version
## Not run: localBoxes <- vmrLocalBoxList() print(localBoxes) ## End(Not run)
## Not run: localBoxes <- vmrLocalBoxList() print(localBoxes) ## End(Not run)
Removes old versions of installed boxes.
vmrLocalBoxPrune()
vmrLocalBoxPrune()
a data.frame of still installed boxes (Name, Poviders and Version)
## Not run: vmrLocalBoxPrune() ## End(Not run)
## Not run: vmrLocalBoxPrune() ## End(Not run)
Remove a specific box from localhost.
vmrLocalBoxRemove(name, provider = "", version = "", force = FALSE)
vmrLocalBoxRemove(name, provider = "", version = "", force = FALSE)
name |
the box name |
provider |
the box provider (default: first provider found) |
version |
the box version (default: version available) |
force |
if TRUE force to remove |
execution code or message
## Not run: lboxes <- vmrLocalBoxList() vmrLocalBoxRemove(lboxes$Name[[1]]) # if multiple providers and versions vmrLocalBoxRemove(lboxes$Name[[1]], lboxes$Provider[[1]], lboxes$Version[[1]]) ## End(Not run)
## Not run: lboxes <- vmrLocalBoxList() vmrLocalBoxRemove(lboxes$Name[[1]]) # if multiple providers and versions vmrLocalBoxRemove(lboxes$Name[[1]], lboxes$Provider[[1]], lboxes$Version[[1]]) ## End(Not run)
Download the latest version of the box use in the current vmr environment.
vmrLocalBoxUpdate()
vmrLocalBoxUpdate()
execution code or message
Mount a host directory to the guest machine.
vmrMountDir(vmr, src = "", dest = "")
vmrMountDir(vmr, src = "", dest = "")
vmr |
a vmr object |
src |
a host directory |
dest |
a destination guest directory |
If the option of mounting a directory is available in the guest provider, it will mount src to destination directory. Calling with no arguments will disable this option.
a vmr object
## Not run: boxes <- vmrList() vmr <- vmrCreate(boxes$Name[1]) vmr <- vmrMountDir(vmr, src = getwd(), dest = "/vmr") vmr <- vmrInitEnv(vmr) vmrStart() ## End(Not run)
## Not run: boxes <- vmrList() vmr <- vmrCreate(boxes$Name[1]) vmr <- vmrMountDir(vmr, src = getwd(), dest = "/vmr") vmr <- vmrInitEnv(vmr) vmrStart() ## End(Not run)
Build a package bundle or binary into the guest machine.
vmrPackageBuild(pkg = "./", binary = FALSE)
vmrPackageBuild(pkg = "./", binary = FALSE)
pkg |
a package directory or a tar.gz file |
binary |
if TRUE build binary package otherwise FALSE |
upload the package and run devtools::build() (build available in $HOME/vmr/package/pkg) in the current vmr environment.
NULL
Perform a package check into the guest
vmrPackageCheck(pkg = "./")
vmrPackageCheck(pkg = "./")
pkg |
a package directory or a tar.gz file |
upload the package and run devtools::check() into the guest machine. (check available in $HOME/vmr/package/pkg). Checking a directory with multiple files may slower upload, prefer tar.gz file
NULL
## Not run: vmrPackageCheck("vmr_package.tar.gz") ## End(Not run)
## Not run: vmrPackageCheck("vmr_package.tar.gz") ## End(Not run)
Test a package into a guest machine
vmrPackageTest(pkg = "./")
vmrPackageTest(pkg = "./")
pkg |
a package directory or tar.gz |
Perform a package check into the guest machine of the current vmr environment using devtools::test(). (tests are available in $HOME/vmr/package/pkg)
NULL
Provision a vmr environment.
vmrProvision(cmd = c(), elts = c(), dest = "")
vmrProvision(cmd = c(), elts = c(), dest = "")
cmd |
list of shell commands |
elts |
list of files and/or directories |
dest |
destination of elts (default HOME/vmr) |
Upload 'elts' files and/or directories to the guest machine 'dest' from the current vmr environment. And finaly run shell commands 'cmd' in the guest machine.
NULL
remove a snapshot of the guest machine
vmrRemoveSnapshot(snap_name)
vmrRemoveSnapshot(snap_name)
snap_name |
the snapshot name |
NULL
Restore a snapshot of the guest machine.
vmrRestoreSnapshot(snap_name)
vmrRestoreSnapshot(snap_name)
snap_name |
the snapshot name |
the snapshot name
## Not run: vmrRestoreSnapshot("my snapshot") ## End(Not run)
## Not run: vmrRestoreSnapshot("my snapshot") ## End(Not run)
Resume a stopped guest machine.
vmrResume()
vmrResume()
In the current vmr environment, start a stopped ([vmrSuspend()
]) guest machine.
NULL
Send files and/or directories to the guest machine in the current vmr environment. They are upload into ~/vmr/ directory.
vmrSend(elt = c())
vmrSend(elt = c())
elt |
list of files and directories |
0 if OK, message otherwise
## Not run: vmrSend(c("myfile")) ## End(Not run)
## Not run: vmrSend(c("myfile")) ## End(Not run)
Set verbose level for vmr package functions
vmrSetVerbose(verbose_mode = "Normal")
vmrSetVerbose(verbose_mode = "Normal")
verbose_mode |
"None", "Normal" or "Full" |
Three verboses mode is available:
"None" : print nothings
"Normal" : print essential
"Full" : print all
invisible verbose value
Start a guest virtual machine using the current vmr environment (directory and Vagrantfile template)
vmrStart()
vmrStart()
the vmr environment unique id
## Not run: lboxes <- vmrList() vmr <- vmrCreate(lboxes$Name[1]) vmr <- vmrInitEnv(vmr) vmrStart() vmrStop() ## End(Not run)
## Not run: lboxes <- vmrList() vmr <- vmrCreate(lboxes$Name[1]) vmr <- vmrInitEnv(vmr) vmrStart() vmrStop() ## End(Not run)
Print guest machine state in the current vmr environment.
vmrStatus()
vmrStatus()
a data.frame with Name, Provider and state
Stop a guest virtual machine in the current vmr environment.
vmrStop(force = FALSE)
vmrStop(force = FALSE)
force |
if TRUE force to stop (powerOff), otherwise FALSE clean shutdown |
NULL
## Not run: lboxes <- vmrList() vmr <- vmrCreate(lboxes$Name[1]) vmr <- vmrInitEnv(vmr) vmrStart() vmrStop() ## End(Not run)
## Not run: lboxes <- vmrList() vmr <- vmrCreate(lboxes$Name[1]) vmr <- vmrInitEnv(vmr) vmrStart() vmrStop() ## End(Not run)
Save the guest machine and stop it.
vmrSuspend()
vmrSuspend()
In the current vmr environment, save the state of the guest machine and stop it.
NULL
Take a snapshot of the guest machine.
vmrTakeSnapshot(snap_name)
vmrTakeSnapshot(snap_name)
snap_name |
the name given to the snapshot |
the snapshot name (invisible)
## Not run: vmrTakeSnapshot("my snapshot") ## End(Not run)
## Not run: vmrTakeSnapshot("my snapshot") ## End(Not run)
Force to use the latest box version of the current vmr environment.
vmrUpdateEnvVersion(vmr)
vmrUpdateEnvVersion(vmr)
vmr |
a vmr object |
Put vmr object version to latest and update the Vagrant File template. Download the new box version if needed.
a vmr object
## Not run: boxes <- vmrList() vmr <- vmrCreate(boxes$Name[1], version = "oldone") vmr <- vmrInitEnv(vmr) # update to latest vmr <- vmrUpdateEnvVersion(vmr) vmrStart() ## End(Not run)
## Not run: boxes <- vmrList() vmr <- vmrCreate(boxes$Name[1], version = "oldone") vmr <- vmrInitEnv(vmr) # update to latest vmr <- vmrUpdateEnvVersion(vmr) vmrStart() ## End(Not run)
Updates R packages installed in the guest machine.
vmrUpdatePackages()
vmrUpdatePackages()
Will perform a update.packages()
in the guest machine
of the current vmr environment.
## Not run: lboxes <- vmrList() vmr <- vmrCreate(lboxes$Name[1]) vmr <- vmrInitEnv(vmr) vmrStart() vmrUpdatePackages() ## End(Not run)
## Not run: lboxes <- vmrList() vmr <- vmrCreate(lboxes$Name[1]) vmr <- vmrInitEnv(vmr) vmrStart() vmrUpdatePackages() ## End(Not run)