# Spotfire SPK Versioning

You create the SPK (.spk) file containing the packages you want to distribute to others using Spotfire Analyst, or to install on a service running on a Spotfire Server node. You might need to change or update the packages that you distribute, which requires changing the version of the Spotfire .spk file.

You can create or change a Spotfire .spk file using TERR or from a text editor. The TERR functions `buildSPK` and `buildServerSPK` create the Spotfire .spk file using the versioning rule details for the following tasks.
Note: The SPK property `BuiltVersion` is NOT the same as the package version. That information is stored in the package DESCRIPTION file. `BuiltVersion` is always specified as four components (`N.n.n.n`).

You can learn more about the TERR functions `buildSPK` and `buildServerSPK` by reading their help files. See Obtaining the SpotfireSPK toolset for more information.

Note: As of TERR version 5.1, the SPK you create by calling `buildSPK` or `buildServerSPK` also includes Imports and Depends packages.

Task | Example | Notes and Results
--- | --- | ---
Create a new DCF for a new SPK containing packages to put on the Spotfire Server. | From the TERR console, install the required packages, and then create the SPK.
    #load the library containing
    #the tools
    library(SpotfireSPK)

    #install the packages to go
    # into the SPK
    install.packages(c("plyr","zoo"))

    #create the DCF containing
    # the package names
    writeLines("Packages: plyr,zoo", "ServerSPK.dcf")

    #create the SPK to upload to the
    # Spotfire Server
    buildServerSPK("ServerSPK.dcf", "ServerSPK.spk")
| A DCF with the name ServerSPK.dcf is created containing the package names listed in the `text` argument of `writeLines`, along with their required and dependent packages. The specified packages are included in the SPK. The SPK `BuiltVersion` number is listed in the DCF as follows.
    "BuiltVersion: 1.0.0.0"
Tip: You can see the `BuiltVersion` by opening the DCF in a text editor, or by calling `readLines`:
    readLines("ServerSPK.dcf")
Add packages to an existing SPK to put on Spotfire Server. | Using a text editor, open the existing DCF, and add to the package names to the list of the (installed) packages to put in the SPK. Do not edit any other part of the DCF. `Packages: plyr,zoo,caret,forecast` From the TERR console, create the SPK.
    #create the SPK to upload to the
    # Spotfire Server
    buildServerSPK("ServerSPK.dcf", "ServerSPK.spk",
    spkName = "Official Package List")
| The DCF with the name ServerSPK.dcf is overwritten, and the packages you manually added to the DCF are added to the SPK. The SPK `BuiltVersion` is changed to the next minor version number and is listed in the DCF. For example:
    "BuiltVersion: 1.1.0.0"
Remove a package from the existing SPK (and subsequently from Spotfire Server). | Using a text editor, open the existing DCF, and remove the unwanted package names from the list the names of the packages to put in the SPK. Do not edit any other part of the DCF. `Packages: plyr` From the TERR console, create the SPK.
    #create the SPK to upload to the
    # Spotfire Server
    buildServerSPK("ServerSPK.dcf", "ServerSPK.spk",
    spkName = "Official Package List")
| The DCF with the name ServerSPK.dcf is overwritten, and only the packages remaining in the DCF are included in the SPK. The SPK `BuiltVersion` is changed to the next major version number and listed in the DCF. For example:
    "BuiltVersion: 2.0.0.0"
Assign a specific `BuiltVersion` number to an SPK. | From the TERR console, install the required packages, and then create the SPK.
    #load the library containing
    # the tools
    library(SpotfireSPK)

    #install the required packages
    install.packages(c("plyr","zoo"))

    #create the DCF containing
    # the packages
    writeLines("Packages: plyr,zoo", "ServerSPK.dcf")

    #create the SPK to upload to the
    # Spotfire Server,
    #passing in the version number.
    #This argument is a character string or a
    #numeric_version object containing four components
    buildServerSPK("ServerSPK.dcf", "ServerSPK.spk", version="1.2.3.4")
| The DCF with the name ServerSPK.dcf is created (or overwritten if it already existed), and the packages specified in the DCF are included in the SPK. The SPK `BuiltVersion` is set to the value passed in for the argument version. For example:
    "BuiltVersion: 1.2.3.4"
Generate a new DCF with the same name. | From the TERR console, install the required packages, and then create the SPK.
    #load the library containing
    # the tools
    library(SpotfireSPK)

    #install the packages to go into
    # the SPK
    install.packages(c("forecast","caret"))

    #create the DCF containing the
    # names of the installed
    # packages
    writeLines("Packages: forecast,caret", "ServerSPK.dcf")

    #create the SPK to upload to the
    # Spotfire Server
    buildServerSPK("ServerSPK.dcf", "ServerSPK.spk")
| Important: If you use this method to overwrite an existing DCF, the version number is still set to `1.0.0.0`; therefore, Spotfire Server does not register the package as a new one, so it does not distribute the new packages to the users. The DCF with the name ServerSPK.dcf is overwritten, and the package names listed in the `text` argument of `writeLines`, along with their required and dependent packages, are included. The packages specified are included in the SPK. The SPK `BuiltVersion` number is listed in the DCF as follows:
    "BuiltVersion: 1.0.0.0"